Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4042852
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T13:03:24+00:00 2026-05-20T13:03:24+00:00

When creating new resources in my REST API I want to give the user

  • 0

When creating new resources in my REST API I want to give the user the possibility to request an empty resource that already contains some default values. Since it doesn’t have an ID per se I am not entirely sure about a RESTful URI that I could use though. Some ideas:

http://example.com/resource/_
http://example.com/resource/__new

Any suggestions or experience with that issue?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T13:03:25+00:00Added an answer on May 20, 2026 at 1:03 pm

    I think that this is more a UI-thing than an API-thing – i.e. the UI should pre-fill the default values into respective form fields for the user, who would then just fill in the blanks and customize the default values if necessary. This is not however applicable everywhere (e.g. when you only have an API without the UI bit).

    You already suggested some options yourself – these would work, however assuming that you can access existing resources as /resource/123, both options would break your URI design at least a bit. I can think of three alternatives on how to approach this, the last (third) one might be the best choice.

    Approach #1
    A better approach might be to mimic the way how time-intensive tasks are usually done in REST. You usually have a resource to which you POST a task, the service then replies with a task URI which you can use later to check on the progress of the task. We can adapt it to our case – define the empty resources with default values as a new resource which we can use to get a “template” for a different resource.

    Example:
    Assuming that you want to get a template for a resource called “user”. You would first do a POST request to the template resource and indicate the type of the resource for which you want to create a “template”:

    POST /template/
    
    <?xml version="1.0" encoding="UTF-8" ?>
    <template>
        <type>user</type>
    </template>
    

    The API would create a new “default” resource for the specified type, in case of success it would respond with:

    HTTP/1.1 204 No Content
    Location /user/123
    

    The location specified in your API’s reply would then contain the template for the resource:

    GET /user/123
    
    <?xml version="1.0" encoding="UTF-8" ?>
    <user>
        <id>123</id>
        <name />
        <email />
        <preferred-language>en</preferred-language>
        <timezone>UTC</timezone>
        ...
    </user>
    

    Approach #2
    Approach #1 already creates a resource for you. An alternative approach is to allow users access to get templates on a specific URI.

    Example:

    GET /template/user
    
    <?xml version="1.0" encoding="UTF-8" ?>
    <user>
        <name />
        <email />
        <preferred-language>en</preferred-language>
        <timezone>UTC</timezone>
        ...
    </user>
    

    Approach #3
    There is one more alternative – I believe it’s the simplest and most logical approach, but it may not be suitable for all cases. You can create a empty resource with defaults by doing a POST request directly to the resource which you want to work with. One downside might be that this will not allow users to just view a template (which they could in approach #1), it will always create a resource for them (similarly as approach #1).

    Example:
    In order to get a default version of a resource you would send an empty POST request to that resource:

    POST /user/
    

    The API would create a new resource with default values and respond with:

    HTTP/1.1 204 No Content
    Location /user/123
    

    Same as in approach #1, the URI would allow the user to fetch the created resource and then alter it as needed (via PUT):

    GET /user/123
    
    <?xml version="1.0" encoding="UTF-8" ?>
    <user>
        <id>123</id>
        <name />
        <email />
        <preferred-language>en</preferred-language>
        <timezone>UTC</timezone>
        ...
    </user>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have such view that handles user registration. After creating new user i want
I have some conditional formatting styles. I don't want to keep creating new rules
I'm working on a new REST-ful API who's primary/only consumer will be a smart/non-web-browser
I'm trying to implement a REST API to my website. My problem is that
I'm creating new option menu inside fragment but after reading http://developer.android.com/resources/articles/avoiding-memory-leaks.html which said to
I have problem creating new instance of excel 2007 using VBA (from Access 2002).
When I'm creating new project with GWT plug in it creates a skeleton project
I'm creating new Site Definitions using this method: http://weblogs.asp.net/paulballard/archive/2007/04/09/creating-a-custom-sharepoint-2007-portal-site-definition-using-the-portalprovisioningprovider-class.aspx and when they get created,
Can I avoid third party code from creating new threads, starting new VMs, or
I need UNION two tables with creating new field, where 1 for first table,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.