ruby-grape / grape-entity

An API focused facade that sits on top of an object model.
MIT License
715 stars 153 forks source link

Proxy API modeling #345

Closed stanleyyuenyiu closed 3 years ago

stanleyyuenyiu commented 3 years ago

Is it possible to use it over on a proxy api inside the grape?

for example:

Let say I have a API, it will call another 3rd party restful API, and I want to model the response with an custom entity, how should I do that

Say the 3rd part API will return { items: [ {id:111} ], page: 1, total:3 }

And the model looks like

class ItemListEntity < Grape::Entity
  present_collection true
  expose :items, using: ItemEntity
  expose :page,
  expose :total
end
class ItemEntity < Grape::Entity
  expose :id
end

And i format it by

result = find_items_from_api
present Hashie::Mash.new(result), with: ItemListEntity

But it doesn't work

LeFnord commented 3 years ago

please use ruby-grape for questions