Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Building an API using 
Presented By 
Visnupriya. J. R
©2014 
Agenda 
•What is Grape 
•Basic Usage 
•Versioning 
•Format 
•Error Handling 
•Restful-Model-Presentation 
•Testing ...
•Powerful API framework 
•Designed to run on Rack Application 
•To fit into Sinatra and Rails Application 
•Grape framewor...
©2014 
Basic Usage 
module API 
class Events < Grape::API 
version 'v1‘ 
get :hello do 
{ hello: "Spritle" } 
end 
end 
en...
©2014 
Versioning 
•Path 
•Header 
•Accept-Version Header 
•Parameter
content_type :xml, ‘application/xml’ 
content_type :json, 'application/json‘ 
default_format :json ##Override default 
for...
error! ‘Access Denied’, 401 
### return JSON format 
error!({error: “unexpected error”, detail: 
“missing widget”}, 500) 
...
©2014 
Restful-Model-Presentation 
•To represent data using 
‘present’ method 
–Grape Entities 
–Hypermedia 
–Rabl 
–Activ...
•Can test API using RSpec 
•RSpec supports API testing framework 
with airborne gem 
•https://github.com/brooklynDev/airbo...
•Easily can document API using Swagger 
•What is Swagger? 
•It’s provide web interface using 
Swagger UI 
•Run doc at 
htt...
©2014 
More…. 
•Helper method 
•Description 
•Pagination with kaminari 
•Cache 
•Content Negotiation 
•OAuth 1.0/2.0
References 
•https://github.com/intridea/grape/wiki 
•https://github.com/intridea/grape#wh 
at-is-grape 
•http://confreaks...
©2014 
Q&A?
©2014 
WE 
BUILD 
APPS 
THAT 
PEOPLE 
LOVE TO 
USE 
Cross-Platform Business Mobile 
Apps Development 
Enterprise Web Appli...
Upcoming SlideShare
Loading in …5
×

Building an API using Grape

903 views

Published on

To describe what is Grape and walk-through with sample

Published in: Software
  • Be the first to comment

  • Be the first to like this

Building an API using Grape

  1. 1. Building an API using Presented By Visnupriya. J. R
  2. 2. ©2014 Agenda •What is Grape •Basic Usage •Versioning •Format •Error Handling •Restful-Model-Presentation •Testing •Documentation
  3. 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. 4. ©2014 Basic Usage module API class Events < Grape::API version 'v1‘ get :hello do { hello: "Spritle" } end end end
  5. 5. ©2014 Versioning •Path •Header •Accept-Version Header •Parameter
  6. 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. 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
  8. 8. ©2014 Restful-Model-Presentation •To represent data using ‘present’ method –Grape Entities –Hypermedia –Rabl –Active Model Serializers
  9. 9. •Can test API using RSpec •RSpec supports API testing framework with airborne gem •https://github.com/brooklynDev/airbor ne ©2014 Write Testing
  10. 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. 11. ©2014 More…. •Helper method •Description •Pagination with kaminari •Cache •Content Negotiation •OAuth 1.0/2.0
  12. 12. References •https://github.com/intridea/grape/wiki •https://github.com/intridea/grape#wh at-is-grape •http://confreaks.com/videos/475- rubyconf2010-the-grapes-of-rapid •http://funonrails.com/2014/03/building-restful- ©2014 api-using-grape-in-rails/ •http://intridea.github.io/grape/docs/
  13. 13. ©2014 Q&A?
  14. 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

×