ruby-grape / ruby-grape/grape

Grape DSL: Return different entities

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

Nobody has claimed this yet.

feature request needs info
Dominant language
Ruby
Stars
10k
Forks
1.2k
Avg merge
14h 38m
Merged PRs (30d)
92

Description

Consider an API endpoint which returns a different entity depending on the current user. Is it possible to specify those different return entities in Grape DSL? Something like the following?

desc 'Return user details' do
  success Entities::BasicUser, Entities::FullUser
end
get 'users' do
  if is_admin
    present users, with: Entities::FullUser
  else
    present users, with: Entities::BasicUser
  end
end

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 reading the Grape DSL handling for success declarations and the entity selection used by present. Compare how the example's Entities::BasicUser and Entities::FullUser would be represented for one endpoint. Done means determining and documenting or implementing a supported way to declare different return entities based on the current user.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
api
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.