ruby-grape / ruby-grape/grape

Api description success entity status code

Open
#1,238 2 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

discuss!
Dominant language
Ruby
Stars
10k
Forks
1.2k
Avg merge
14h 38m
Merged PRs (30d)
92

Description

Hello,

I wanted to discuss and optional pull request about http status codes. Mainly because I often notice success status codes are often not properly documented in most tooling. This would also be an awesome feature for documentation tools.

Grape returns a standard 200 on get, put, patch, delete requests and a 201 on post requests. This is great for me. Tough you can override status codes on successful requests. Shouldn't we be able to describe it?

For example someone wants:

post do
  some_method
  status 202
end

Maybe we can introduce a status code in the description like:

desc 'Some method.' do
  success API::Entities::Entity
  status_code 202
  failure [[401, 'Unauthorized', 'Entities::Error']]
end
post do
  some_method
  status 202
end

Or a more failure like syntax:

desc 'Some method.' do
  success [202, 'Ok', API::Entities::Entity]
  failure [[401, 'Unauthorized', 'Entities::Error']]
end
post do
  some_method
  status 202
end

Finally, we can even refactor out the status in the post body to automatically return the defined success status code.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the desc block and its existing success and failure declarations, then compare them with the request's status call. Done requires a decided syntax for documenting custom success status codes and agreement on whether the declared status should also change response behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
api, documentation
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.