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 8169647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T20:54:38+00:00 2026-06-06T20:54:38+00:00

A number of the developers here are having a friendly (some would say religious)

  • 0

A number of the developers here are having a friendly (some would say religious) discussion about whether a GET request from a RESTful API should return the ID of the requested resource. Let’s assume the following GET request:

http://my.api.com/rest/users/23

This currently returns:

{"name": "Jim", "age": 40, "favoriteColor": "blue"}

Note that “id” is missing from the result set.

There are basically 4 camps battling with this issue.

CAMP #1: When callers make the GET request, they already know the ID. Therefore, the result set should not include the ID. If callers need this data to enable UI editing, then callers needs to pass through the ID 23, perhaps adding the member {“id”: 23} to the JSON manually.
Folks in Camp #1 also argue that the presence of the ID in the result set would indicate that this value can be modified, which of course it can’t.

CAMP #2: Without the ID, the JSON result set can’t be used natively for edit/update operations in UI forms. Instead, the AJAX callback mechanism needs to be responsible for passing around ID fields and manually adding these to the result set. This seems klunky and error prone. The UI guys are making the argument that the result set “feels” like it’s missing data that should be present, namely the ID.

CAMP #3: These folks are concerned about consistency. If we ever have a collection of user objects returned by an API, these objects MUST include the ID. Therefore, for consistency, the singleton version of a GET should also include the ID.

CAMP #4: These folks are suggesting that the GET request for a user could return meta data in the form of HyperMedia or SelfLinks that would include the ID.

This isn’t an esoteric “Who’s Right?” argument, either. The approach we take will dictate the shape of our API and affect the work loads of several developers over the new few weeks.

  • 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-06-06T20:54:40+00:00Added an answer on June 6, 2026 at 8:54 pm

    This is a matter of opinion, which is not the kind of Question that Stackoverflow loves to see. in any case, I will offer mine.

    You are returning the representation of the state of an object or resource. The ID is part of that representation, and therefore ought to be included in the JSON packet. It is a property of the resource. Whether the caller knows the ID or not is not particularly germane to the discussion. CAMP #1 is on shaky ground.

    The point you raise about collections is very relevant. Does it make sense to use one representation for the retrieve-1 operation, and another representation for the retrieve-N operation? I think not.

    However, the issue you are confronting is more general – what data should be included in the representation that is transferred to clients, and under what circumstances? In some cases the caller simply does not care about a significant subset of the properties. Especially in scenarios where a large set of objects gets retrieved – where the cost to transmit the data is larger in comparison to the base communication cost – you’d like to optimize what is shipped back.

    All sufficiently mature REST protocols have an ability to shape the returned data.

    For examples, see

    • the Facebook Graph API, http://developers.facebook.com/docs/reference/api/
    • the StackExchange API v2.0 – there is a “filter” object you can pass to precisely shape what gets returned.
    • the CouchDb API – has a map function for every view, which determines what data gets returned. It also has a blanket query parameter, include_docs, which directs the server to include full objects or just metadata. (In some cases you might want only the count of the data, not the actual data.)

    Facebook allows you to explicitly specify the fields you want.

    enter image description here

    The stackexchange API is interesting. They’ve defined an entirely new type of object to support the shaping. You can use the API to define a “filter” and save it on the server side. Then in your query you pass a filter param with the ID of the filter, and the returned object representations include all the attributes specified in the filter. With no filter you get a “default” subset of fields. To get “all fields” you need to define an all-inclusive filter.

    you can see this in action at https://api.stackexchange.com/docs/answers

    …and specifically see the filter specification dialog.

    enter image description here


    There is no single correct way to do things. You need to balance the complexity of the “shaping” feature you support with the cost to develop and the needs of the apps that will use the API.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to pull some data from the API. It returns the GET in
Copy from drupal.stackexchange.com hoping to get more answers here: I face a rather common
A number of our users have just upgraded from IE6 to IE7. the upgreaded
There are a number of discussions on stackoverflow.com about what is the best iPhone
I have recently come across a number of projects where developers have been leaving
I'm beginning my journey with JavaScript and programming in general. Not having many developers
My business partner and I are having issues selecting from a MySQL view that
I think everyone here would agree that in order to be considered a professional
How do we get Unique Device ID from the Android Tablets (Android 3.0 SDK
Recently, I made a post about the developers I'm working with not using try

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.