Skip to content

Instantly share code, notes, and snippets.

@joaquimadraz
Last active August 29, 2015 14:28
Show Gist options
  • Save joaquimadraz/31ef7ab7fe0a73f2fcc0 to your computer and use it in GitHub Desktop.
Save joaquimadraz/31ef7ab7fe0a73f2fcc0 to your computer and use it in GitHub Desktop.
API level validations with Grape
require 'grape'
module Blog
class Web < Grape::API
...
desc "Create post comment"
params do
requires :id, type: Integer
requires :comment, type: Hash do
requires :text, type: String
end
end
post '/api/v0/posts/:id/comments/' do
context = UseCases::Comments::Create::Base.perform(params)
status 409 if context.status.conflict?
status 201 if context.status.created?
context.data
end
...
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment