Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal for 201 Created responses #32

Open
octomad opened this issue Nov 15, 2021 · 3 comments
Open

Proposal for 201 Created responses #32

octomad opened this issue Nov 15, 2021 · 3 comments

Comments

@octomad
Copy link
Collaborator

octomad commented Nov 15, 2021

Hyperion spec makes no mention of what type of response a 201 should be sending back. In order to reach some type consistency across all Hyperion compliant APIs there should be a standard in place for this.

According to the HTTP spec:

... a Location header field in the response or, if no Location field is received, by the effective request URI. The 201 response payload typically describes and links to the resource(s) created

According to Mozilla's dev site

The HTTP 201 Created success status response code indicates that the request has succeeded and ... the new resource is returned in the body of the message, its location being either the URL of the request, or the content of the Location header.

Both of those references have similarities but also some differences -- most notably the mention of what the body/payload should include. We should lean towards what former HTTP spec mentions however it does leave some room for interpretation using words like "typically describes" and not a MUST. The Location header is common and should be part of the headers.

Given this, I see three possible avenues that an API can take. Return a Location header along with:

  1. No response body - not terribly useful
  2. Full / partial resource returned - most clients don't use the resource returned here. In edge cases where a client needs the new resource, then can go back and GET it. This saves the API server (and developers) from having to re-query the state from the data store.
  3. Hyperion LinkValue to the new resource - While redundant with the HTTP specification, this appears to be the most Hyperion-esque. Not only do APIs benefit from not having to re-query, the response provides useful information about where the new resource is located.

An example header + payload response for option 3 could be:

HTTP/1.1 201 Created
Date: Sun, 10 Nov 2021 23:26:07 GMT
Server: AWSGW Server...
Location: https://api.sample.com/apis/3d3f9275-a2bc-4fcc-be7b-a229f1d85ed3/specs/6e17e006-eddb-4c24-9618-94ad5d28c9b4

{
    "@type": "NodeRef",
    "@links" : {
        "location": {
            "href": "/apis/3d3f9275-a2bc-4fcc-be7b-a229f1d85ed3/specs/6e17e006-eddb-4c24-9618-94ad5d28c9b4",
            "description": "A reference to the new API Specification"
        }
    }
}
@teehill
Copy link
Contributor

teehill commented Nov 16, 2021

Personally I vote to keep our convention of @id

@octomad
Copy link
Collaborator Author

octomad commented Nov 16, 2021

the problem that i had with @id is that it represents the current document being returned. In this case, it isn't referring to the current doc but rather a ref to the resource that was created.

@teehill
Copy link
Contributor

teehill commented Nov 16, 2021

@id isn't solely for representing the current resource, it's used as a reference in other places (like Collections). It's our version of hypertext navigation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants