More Related Content Similar to Building an API using Grape (20) Building an API using Grape2. ©2014
Agenda
•What is Grape
•Basic Usage
•Versioning
•Format
•Error Handling
•Restful-Model-Presentation
•Testing
•Documentation
3. •Powerful API framework
•Designed to run on Rack Application
•To fit into Sinatra and Rails Application
•Grape framework mean "Generalized
Rapid API Erector"
©2014
What is Grape?
4. ©2014
Basic Usage
module API
class Events < Grape::API
version 'v1‘
get :hello do
{ hello: "Spritle" }
end
end
end
6. content_type :xml, ‘application/xml’
content_type :json, 'application/json‘
default_format :json ##Override default
format
format :json ## for single format
©2014
API Format
•Support XML, JSON, BINARY,
and TXT content-types
•Default format is :txt
7. 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
©2014
Error Handling
9. •Can test API using RSpec
•RSpec supports API testing framework
with airborne gem
•https://github.com/brooklynDev/airbor
ne
©2014
Write Testing
10. •Easily can document API using Swagger
•What is Swagger?
•It’s provide web interface using
Swagger UI
•Run doc at
http://localhost:3000/apidoc
©2014
Documentation
11. ©2014
More….
•Helper method
•Description
•Pagination with kaminari
•Cache
•Content Negotiation
•OAuth 1.0/2.0
14. ©2014
WE
BUILD
APPS
THAT
PEOPLE
LOVE TO
USE
Cross-Platform Business Mobile
Apps Development
Enterprise Web Applications
Development
Social Media Integrated
Applications Development
Product Development Services