Use grape-entity as request body for PUT, POST, PATCH with validation

145 views
Skip to first unread message

Emanoel Xavier

unread,
Jun 7, 2018, 2:03:03 PM6/7/18
to Grape Framework Discussion
I am attempting to use grape-entity as a request body for PUT, POSt, PATCH. It seems this is the best way to get param_type body as the `params` block does not currently support that neatly (i.e.: arrays). However when doing something like the code below there is no validation happening. What is the recommended way to get both (validation and `body` param type)? I came across this related StackOverflow question https://stackoverflow.com/questions/29517362/grape-required-params-with-grape-entity  but there does not seem to be a consensus on how this should work. 

module Api
  class Accounts < Grape::API
    desc 'createTestAccount',
       params: Entity::Accounts.documentation
    post 'create' do
      JSON(params)
    end
  end
end
Reply all
Reply to author
Forward
0 new messages