Created
November 12, 2014 14:52
-
-
Save jhollinger/b1b64357a9fc8caec3c2 to your computer and use it in GitHub Desktop.
Sample Grape/Swagger Cat API
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 './main' | |
run API::Root |
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 'bundler/setup' | |
Bundler.require(:default) | |
module API | |
module Entities | |
class Pajamas < Grape::Entity | |
expose :id, documentation: {type: 'integer'} | |
expose :color, documentation: {type: 'string', desc: 'The color'} | |
end | |
class Cat < Grape::Entity | |
expose :id, documentation: {type: 'integer'} | |
expose :name, documentation: {type: 'string', desc: "The cat's name"} | |
expose :pajamas, using: API::Entities::Pajamas, | |
documentation: {type: 'API::Pajamas', desc: "The cat's pajamas"} | |
end | |
end | |
class Cats < Grape::API | |
version 'v1' | |
get :cats, | |
http_codes: [[200, 'Ok', API::Entities::Cat]] do | |
present [], with: API::Entities::Cat | |
end | |
end | |
class Root < Grape::API | |
before do | |
header['Access-Control-Allow-Origin'] = '*' | |
header['Access-Control-Request-Method'] = '*' | |
end | |
mount API::Cats | |
add_swagger_documentation | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment