Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Curl Request
- # curl -X POST -H "Content-Type:application/json" 0:9292/v1/articles -d '{"title":"hello","body":"world"}'
- # {"error":"article is missing"}
- # curl -X POST -H "Content-Type:application/json" 0:9292/v1/articles -d '{"article":{"title":"hello","body":"world"}}'
- # {"error":"article is invalid"}
- # Entity
- module API
- module Entities
- class Article < Grape::Entity
- expose :title, documentation: { type: 'string', desc: 'Title' }
- expose :body, documentation: { type: 'string', desc: 'Body' }
- end
- end
- end
- # API
- desc "Create an article"
- params do
- requires :article, type: API::Entities::Article, documentation: { example: "aklsdfj" }
- end
- post '/articles' do
- puts params
- article = Article.create(params(:title, :body))
- represent(article, env)
- end
- # Add Swagger Docs
- add_swagger_documentation mount_path: 'api/doc',
- api_version: 'v1',
- markdown: GrapeSwagger::Markdown::KramdownAdapter,
- hide_documentation_path: true,
- base_path: Application.config.base_path,
- models: [API::Entities::Article]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement