ruby-grape / grape

An opinionated framework for creating REST-like APIs in Ruby.
http://www.ruby-grape.org
MIT License
9.89k stars 1.22k forks source link

Grape DSL: Return different entities #1513

Open Razer6 opened 8 years ago

Razer6 commented 8 years ago

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
dblock commented 8 years ago

Generally I don't recommend APIs that return two different things. But I think this should be possible - give it a try, if not it should be a feature request.

LeFnord commented 8 years ago

short answer: actual it isn't possible, and it isn't recommended longer answer: it should not be possible

why not? have in mind what this means … a logic would be implemented for this feature, ok but this logic must also be handled on the consumer and documentation side, cause it is common sense to expect one resource and changes, which removes common behaviour are breaking changes, means exactly: please make also feature request for: