SlideShare a Scribd company logo
1 of 14
Building an API using 
Presented By 
Visnupriya. J. R
©2014 
Agenda 
•What is Grape 
•Basic Usage 
•Versioning 
•Format 
•Error Handling 
•Restful-Model-Presentation 
•Testing 
•Documentation
•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?
©2014 
Basic Usage 
module API 
class Events < Grape::API 
version 'v1‘ 
get :hello do 
{ hello: "Spritle" } 
end 
end 
end
©2014 
Versioning 
•Path 
•Header 
•Accept-Version Header 
•Parameter
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
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
©2014 
Restful-Model-Presentation 
•To represent data using 
‘present’ method 
–Grape Entities 
–Hypermedia 
–Rabl 
–Active Model Serializers
•Can test API using RSpec 
•RSpec supports API testing framework 
with airborne gem 
•https://github.com/brooklynDev/airbor 
ne 
©2014 
Write Testing
•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
©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.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/
©2014 
Q&A?
©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

More Related Content

What's hot

Picking gem ruby for penetration testers
Picking gem ruby for penetration testersPicking gem ruby for penetration testers
Picking gem ruby for penetration testers
Paolo Perego
 

What's hot (20)

Windows Containers - Microsoft Ignite The Tour
Windows Containers - Microsoft Ignite The TourWindows Containers - Microsoft Ignite The Tour
Windows Containers - Microsoft Ignite The Tour
 
Don't worry be API with Slim framework and Joomla
Don't worry be API with Slim framework and JoomlaDon't worry be API with Slim framework and Joomla
Don't worry be API with Slim framework and Joomla
 
Ruby on Rails workshop for beginner
Ruby on Rails workshop for beginnerRuby on Rails workshop for beginner
Ruby on Rails workshop for beginner
 
Building a scalable API with Grails
Building a scalable API with GrailsBuilding a scalable API with Grails
Building a scalable API with Grails
 
Picking gem ruby for penetration testers
Picking gem ruby for penetration testersPicking gem ruby for penetration testers
Picking gem ruby for penetration testers
 
The Evolution of Airbnb's Frontend
The Evolution of Airbnb's FrontendThe Evolution of Airbnb's Frontend
The Evolution of Airbnb's Frontend
 
Asp.Net Core MVC , Razor page , Entity Framework Core
Asp.Net Core MVC , Razor page , Entity Framework CoreAsp.Net Core MVC , Razor page , Entity Framework Core
Asp.Net Core MVC , Razor page , Entity Framework Core
 
Laravel 5 Annotations: RESTful API routing
Laravel 5 Annotations: RESTful API routingLaravel 5 Annotations: RESTful API routing
Laravel 5 Annotations: RESTful API routing
 
Cocoa on-rails-3rd
Cocoa on-rails-3rdCocoa on-rails-3rd
Cocoa on-rails-3rd
 
AngularJS meets Rails
AngularJS meets RailsAngularJS meets Rails
AngularJS meets Rails
 
Intro to Laravel
Intro to LaravelIntro to Laravel
Intro to Laravel
 
Rhodes
RhodesRhodes
Rhodes
 
How angularjs saves rails
How angularjs saves railsHow angularjs saves rails
How angularjs saves rails
 
IVS CTO Night And Day 2018 Winter - [re:Cap] Serverless & Mobile
IVS CTO Night And Day 2018 Winter - [re:Cap] Serverless & MobileIVS CTO Night And Day 2018 Winter - [re:Cap] Serverless & Mobile
IVS CTO Night And Day 2018 Winter - [re:Cap] Serverless & Mobile
 
Ruby w/o Rails (Олександр Сімонов)
Ruby w/o Rails (Олександр Сімонов)Ruby w/o Rails (Олександр Сімонов)
Ruby w/o Rails (Олександр Сімонов)
 
Service Oriented Applications
Service Oriented ApplicationsService Oriented Applications
Service Oriented Applications
 
Using RESTFUL APIs in ANGULARJS
Using RESTFUL APIs in ANGULARJSUsing RESTFUL APIs in ANGULARJS
Using RESTFUL APIs in ANGULARJS
 
Spring Boot Update
Spring Boot UpdateSpring Boot Update
Spring Boot Update
 
Swagger UI
Swagger UISwagger UI
Swagger UI
 
Ruby On Rails
Ruby On RailsRuby On Rails
Ruby On Rails
 

Similar to Building an API using Grape

Getting Started with the WSO2 API Manager
Getting Started with the WSO2 API ManagerGetting Started with the WSO2 API Manager
Getting Started with the WSO2 API Manager
WSO2
 
REST API 20.2 - Appworks Gateway Integration.pptx
REST API 20.2 - Appworks Gateway Integration.pptxREST API 20.2 - Appworks Gateway Integration.pptx
REST API 20.2 - Appworks Gateway Integration.pptx
Jason452803
 
Getting Started with the WSO2 manager
Getting Started with the WSO2  managerGetting Started with the WSO2  manager
Getting Started with the WSO2 manager
WSO2
 

Similar to Building an API using Grape (20)

Document your rest api using swagger - Devoxx 2015
Document your rest api using swagger - Devoxx 2015Document your rest api using swagger - Devoxx 2015
Document your rest api using swagger - Devoxx 2015
 
Getting Started with the WSO2 API Manager
Getting Started with the WSO2 API ManagerGetting Started with the WSO2 API Manager
Getting Started with the WSO2 API Manager
 
API Services: Building State-of-the-Art APIs
API Services: Building State-of-the-Art APIsAPI Services: Building State-of-the-Art APIs
API Services: Building State-of-the-Art APIs
 
REST API 20.2 - Appworks Gateway Integration.pptx
REST API 20.2 - Appworks Gateway Integration.pptxREST API 20.2 - Appworks Gateway Integration.pptx
REST API 20.2 - Appworks Gateway Integration.pptx
 
A Journey from API Versioning to Canary Release | Nordic APIs Platform Summit...
A Journey from API Versioning to Canary Release | Nordic APIs Platform Summit...A Journey from API Versioning to Canary Release | Nordic APIs Platform Summit...
A Journey from API Versioning to Canary Release | Nordic APIs Platform Summit...
 
API designing with WSO2 API Manager
API designing with WSO2 API ManagerAPI designing with WSO2 API Manager
API designing with WSO2 API Manager
 
A Journey from API Versioning to Canary Release | APIDays Zurich 2017
A Journey from API Versioning to Canary Release | APIDays Zurich 2017A Journey from API Versioning to Canary Release | APIDays Zurich 2017
A Journey from API Versioning to Canary Release | APIDays Zurich 2017
 
Getting Started with the WSO2 manager
Getting Started with the WSO2  managerGetting Started with the WSO2  manager
Getting Started with the WSO2 manager
 
Developing Apps with Azure AD
Developing Apps with Azure ADDeveloping Apps with Azure AD
Developing Apps with Azure AD
 
Apigility-powered API's on IBM i
Apigility-powered API's on IBM iApigility-powered API's on IBM i
Apigility-powered API's on IBM i
 
2.0 Client Libraries & Using the Java Client by Noah Crowley, Developer Advoc...
2.0 Client Libraries & Using the Java Client by Noah Crowley, Developer Advoc...2.0 Client Libraries & Using the Java Client by Noah Crowley, Developer Advoc...
2.0 Client Libraries & Using the Java Client by Noah Crowley, Developer Advoc...
 
Using the Java Client Library by Noah Crowley, DevRel | InfluxData
Using the Java Client Library by Noah Crowley, DevRel | InfluxDataUsing the Java Client Library by Noah Crowley, DevRel | InfluxData
Using the Java Client Library by Noah Crowley, DevRel | InfluxData
 
Integrate any Angular Project into WebSphere Portal
Integrate any Angular Project into WebSphere PortalIntegrate any Angular Project into WebSphere Portal
Integrate any Angular Project into WebSphere Portal
 
API Versioning for Zero Downtime | Devoxx Belgium 2017
API Versioning for Zero Downtime | Devoxx Belgium 2017API Versioning for Zero Downtime | Devoxx Belgium 2017
API Versioning for Zero Downtime | Devoxx Belgium 2017
 
Angular2.0@Shanghai0319
Angular2.0@Shanghai0319Angular2.0@Shanghai0319
Angular2.0@Shanghai0319
 
Streamlined Geek Talk
Streamlined Geek TalkStreamlined Geek Talk
Streamlined Geek Talk
 
LF_APIStrat17_The Great API Redesign
LF_APIStrat17_The Great API RedesignLF_APIStrat17_The Great API Redesign
LF_APIStrat17_The Great API Redesign
 
Api clarity webinar
Api clarity webinarApi clarity webinar
Api clarity webinar
 
Api-First service design
Api-First service designApi-First service design
Api-First service design
 
RESTful web APIs (build, document, manage)
RESTful web APIs (build, document, manage)RESTful web APIs (build, document, manage)
RESTful web APIs (build, document, manage)
 

Recently uploaded

%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
VishalKumarJha10
 

Recently uploaded (20)

The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
Generic or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisionsGeneric or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisions
 
%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 

Building an API using Grape

  • 1. Building an API using Presented By Visnupriya. J. R
  • 2. ©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
  • 5. ©2014 Versioning •Path •Header •Accept-Version Header •Parameter
  • 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
  • 8. ©2014 Restful-Model-Presentation •To represent data using ‘present’ method –Grape Entities –Hypermedia –Rabl –Active Model Serializers
  • 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
  • 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/
  • 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