Last active
August 29, 2015 14:28
-
-
Save joaquimadraz/31ef7ab7fe0a73f2fcc0 to your computer and use it in GitHub Desktop.
API level validations with Grape
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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