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

feat: improve response (code) guidance (#787, #762, #737) #789

Merged
merged 1 commit into from
Dec 12, 2023

Conversation

tkrop
Copy link
Member

@tkrop tkrop commented Nov 22, 2023

This pull request was starting from the still open issue #685 (originally addressed by #737) and the latest work done in #787 trying to grab the open ends and missed links to add more guidance on the correct usage of Location header in POST responses. While doing so I was also doing the review on #762, I was lacking behind.

Changes to chapters/http-requests.adoc:

  1. Apply standard formatting rules for asciidoc/markdown and fixes spelling and grammar issues (all major changes are marked with comments and exposed in this list).
  2. Adds 202 as expected response codes on PUT and PATCH operations, since they may also support asynchronous processing.
  3. Adds better advise on how to design POST responses utilizing the Location header.

Changes to chapters/http-status-codes-and-errors.adoc:

  1. Apply standard formatting rules for asciidoc/markdown and fixes spelling and grammar issues (all major changes are exposed in this list and can be easily spotted in the change set).
  2. Improved exception when to document response codes explicitly.
  3. Added advise when 200 response code marks the return of an already existing resource on resource creation.
  4. FIx reference to rule 251 and added it to each effected 3xx response code. Before it incorrectly referenced rule 250 and was added to the chapter of 3xxresponse codes.
  5. Added additional use-advise to response codes 406, 412, 415, 428, 500, and 503 to highlight response codes that have use case defined within the guideline.
  6. Improved advise for response code 423, 500, 501, and 503 giving details on use cases.
  7. Added advise for response codes 424, 431, 502, 504, 505, 507, and 511 to complete the list of response codes defined by the three incorporated and referenced RFCs 9110, 6585, and 4918.

Definitely fixes #685.

Comment on lines +133 to +138
* For a single resource (tree) {POST} is expected to utilize the {Location}
header pointing to the URL of the newly created resource (tree) -- with or
without returning the resource (tree).
* For multiple resources {POST} may either return a collection of newly
created resources as served by the {GET} collection endpoint, or a bulk
response using the status code {207} (see also <<152>>).
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tries to clarify on how to return created resources with respect to id and location.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not convinced that we always should require the Location response header.
Propose the following change:

  • {POST} must be used to create one or multiple new resources:
    • Single resource creation: successful POST should return the new resource
      object as response payload including the resource id. We expect that the resource id
      can be used as a path parameter of the GET endpoint to read the resource. The URL to read
      the resource must be provided via the Location response header, if the resource is
      not returned. It is a good practice to always provide the Location header.
    • Multiple resource creation: successful {POST} may either return a collection of newly
      created resources as served by the {GET} collection endpoint, or a bulk
      response using the status code {207} (see also <<152>>).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #791 for the proposed changes from the discussion.

Comment on lines +224 to +226
* Successful {DELETE} requests return {200} or {204} (if the resource was
deleted -- with or without returning the resource), or {202} (if the request
was accepted for asynchronous processing).
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adds 202.

Comment on lines +176 to +178
* Successful {PATCH} requests return {200} or {204} (if the resource was
updated -- with or without returning the resource), and {202} (if the request
was accepted for asynchronous processing).
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adds 202.

@tfrauenstein
Copy link
Member

👍

1 similar comment
@tkrop
Copy link
Member Author

tkrop commented Dec 12, 2023

👍

@tkrop tkrop merged commit f0ec6a8 into main Dec 12, 2023
2 checks passed
@tkrop tkrop deleted the improve-response-codes branch December 12, 2023 13:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Guide return code usage for (robust) create
4 participants