Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
RESTful API with Grape
Search
Charles Lalonde
May 20, 2016
Programming
0
190
RESTful API with Grape
Charles Lalonde
May 20, 2016
Tweet
Share
Other Decks in Programming
See All in Programming
Jakarta EE meets AI
ivargrimstad
0
580
AI時代におけるSRE、 あるいはエンジニアの生存戦略
pyama86
6
1.1k
Amazon Qを使ってIaCを触ろう!
maruto
0
400
Creating a Free Video Ad Network on the Edge
mizoguchicoji
0
110
役立つログに取り組もう
irof
28
9.6k
Compose 1.7のTextFieldはPOBox Plusで日本語変換できない
tomoya0x00
0
190
Streams APIとTCPフロー制御 / Web Streams API and TCP flow control
tasshi
2
350
Why Jakarta EE Matters to Spring - and Vice Versa
ivargrimstad
0
1k
ピラミッド、アイスクリームコーン、SMURF: 自動テストの最適バランスを求めて / Pyramid Ice-Cream-Cone and SMURF
twada
PRO
10
1.3k
よくできたテンプレート言語として TypeScript + JSX を利用する試み / Using TypeScript + JSX outside of Web Frontend #TSKaigiKansai
izumin5210
6
1.7k
3rd party scriptでもReactを使いたい! Preact + Reactのハイブリッド開発
righttouch
PRO
1
600
Contemporary Test Cases
maaretp
0
130
Featured
See All Featured
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
Building Your Own Lightsaber
phodgson
103
6.1k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
126
18k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
16
2.1k
Why Our Code Smells
bkeepers
PRO
334
57k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.3k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
229
52k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
Ruby is Unlike a Banana
tanoku
97
11k
For a Future-Friendly Web
brad_frost
175
9.4k
What's in a price? How to price your products and services
michaelherold
243
12k
Transcript
RESTful API with Grape
Hi, I’m Charles Rails Developer @ Unsplash
Unsplash Do whatever you want high-resolution photos
None
None
None
None
None
None
Why Grape?
Why Grape? • Framework to build API • Easily extensible
• Supports Rails, Sinatra and others
Setup Rails in 4 simple steps
• app/ • api/ • v1/ • base.rb Create folder
structure Setup Rails in 4 simple steps
Setup Rails in 4 simple steps Auto load the API
files in your application.rb
Mount the API in routes.rb Setup Rails in 4 simple
steps
Setup Rails in 4 simple steps • Versioning • Format
• Endpoint mounting • Default headers • Logs
{ Grape } Basic
{ Grape } Basic • Call Overview • Headers •
Parameters • Http Methods • Error Handling • Helpers
Overview • Resource • Route params • HTTP methods •
Parameters GET api.montrealrb.com/v1/:resource/:route_param
Headers • Useful for bots • Alerting users of deprecated
endpoints • Allow multiple origins • etc
Parameters • Can manage optional and required params • Multiple
parameter types • Custom validation
HTTP methods • Supports all HTTP methods • Specify endpoint
names
Error handling • Message • Status
Helpers • Create reusable code • Can include custom modules
{ Grape } gem extension
{ Grape } gem extension WineBouncer Oauth2 protection with
Doorkeeper https://github.com/antek-drzewiecki/wine_bouncer grape-rails-cache Server side cache https://github.com/monterail/grape-rails-cache grape-swagger Automatically generate documentation https://github.com/ruby-grape/grape-swagger
{ Grape } gem extension
Demo
Unsplash API Stats API Requests 230 740 265 Last 30
days API Developers 2 479 Approved Applications 184
Connect @dechuck on Twitter, GitHub & Unsplash Thanks