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
hotwire_or_react
harunatsujita
6
2.8k
いかにして不足・不整合なくデータ移行したか
tjmtmmnk
1
1k
Vaporモードを大規模サービスに最速導入して学びを共有する
kazukishimamoto
4
4.2k
Vertical Architectures for Scalable Angular Applications
manfredsteyer
PRO
0
290
Android 15 でアクションバー表示時にステータスバーが白くなってしまう問題
tonionagauzzi
0
110
CPython 인터프리터 구조 파헤치기 - PyCon Korea 24
kennethanceyer
0
220
Universal Linksの実装方法と陥りがちな罠
kaitokudou
1
220
生成 AI を活用した toitta 切片分類機能の裏側 / Inside toitta's AI-Based Factoid Clustering
pokutuna
0
530
qmuntal/stateless のススメ
sgash708
0
110
Re:proS_案内資料
rect
0
260
Prompt Engineering for Developers @ AWS Community Day Adria 2024
slobodan
0
120
Progressive Web Apps für Desktop und Mobile mit Angular (Hands-on)
christianliebel
PRO
0
100
Featured
See All Featured
Gamification - CAS2011
davidbonilla
80
5k
Music & Morning Musume
bryan
46
6.1k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
92
16k
How to train your dragon (web standard)
notwaldorf
88
5.6k
Testing 201, or: Great Expectations
jmmastey
38
7k
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
A designer walks into a library…
pauljervisheath
202
24k
Become a Pro
speakerdeck
PRO
24
4.9k
Into the Great Unknown - MozCon
thekraken
31
1.5k
GraphQLの誤解/rethinking-graphql
sonatard
66
9.9k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
9
670
Adopting Sorbet at Scale
ufuk
73
9k
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