building an api using grape
TRANSCRIPT
Presented By
Visnupriya. J. R
Building an API using
©2014
•What is Grape
•Basic Usage
•Versioning
•Format
•Error Handling
•Restful-Model-Presentation
•Testing
•Documentation
Agenda
©2014
•Powerful API framework
•Designed to run on Rack Application
•To fit into Sinatra and Rails Application
•Grape framework mean "Generalized Rapid API Erector"
What is Grape?
©2014
module API
class Events < Grape::API
version 'v1‘
get :hello do
{ hello: "Spritle" }
end
end
end
Basic Usage
©2014
•Path
•Header
•Accept-Version Header
•Parameter
Versioning
©2014
content_type :xml, ‘application/xml’
content_type :json, 'application/json‘
default_format :json ##Override default format
format :json ## for single format
API Format
•Support XML, JSON, BINARY, and TXT content-types
•Default format is :txt
©2014
error! ‘Access Denied’, 401
### return JSON format
error!({error: “unexpected error”, detail: “missing widget”}, 500)
### rescue all exceptions and return in API format
rescue_from :all
Error Handling
©2014
•To represent data using ‘present’ method
–Grape Entities
–Hypermedia
–Rabl
–Active Model Serializers
Restful-Model-Presentation
©2014
•Can test API using RSpec
•RSpec supports API testing framework with airborne gem
•https://github.com/brooklynDev/airborne
Write Testing
©2014
•Easily can document API using Swagger
•What is Swagger?
•It’s provide web interface using Swagger UI
•Run doc at http://localhost:3000/apidoc
Documentation
©2014
•Helper method
•Description
•Pagination with kaminari
•Cache
•Content Negotiation
•OAuth 1.0/2.0
More….
©2014
•https://github.com/intridea/grape/wiki
•https://github.com/intridea/grape#what-is-grape
•http://confreaks.com/videos/475-rubyconf2010-the-grapes-of-rapid
•http://funonrails.com/2014/03/building-restful-api-using-grape-in-rails/
•http://intridea.github.io/grape/docs/
References
©2014
Q&A?
©2014
WE BUILD APPS THAT PEOPLE LOVE TO USE
Enterprise Web Applications Development
Cross-Platform Business Mobile Apps Development
Social Media Integrated Applications Development
Product Development Services