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
170
RESTful API with Grape
Charles Lalonde
May 20, 2016
Tweet
Share
Other Decks in Programming
See All in Programming
Blue/Greenデプロイの導入による 運用フローの改善
kudoas
1
370
Apache Hive 4 on Treasure Data
ryukobayashi
0
170
Node.js v22 で変わること
yosuke_furukawa
PRO
9
3.1k
Ruby Pattern Matching
bkuhlmann
0
920
AWS CDKコントリビュートTIPS / aws-cdk-contribution-tips
gotok365
2
120
デフォルトにして至高、RubyMineの大好きな所
ruzia
0
310
冗長なエラーログを削減し、スタックトレースを手に入れる / Reducing Verbose Error Logs and Obtaining Stack Traces
upamune
0
510
今、知っておきたい! 生成AIエージェントの世界
elith
3
350
PostmanでAPIの動作確認が楽になった話
h455h1
0
170
Fragment Composition of GraphQL
quramy
4
800
大規模UIKitベースアプリへのTCAの段階的導入/gradual-adoption-of-tca-in-a-large-scale-uikit-based-app
takehilo
1
120
PHPの次期バージョンはこの時期どうなっているのか - Internalsの開発体制について - PHPカンファレンス小田原
youkidearitai
PRO
1
190
Featured
See All Featured
Navigating Team Friction
lara
178
13k
What's new in Ruby 2.0
geeforr
337
31k
How to Ace a Technical Interview
jacobian
272
22k
How GitHub (no longer) Works
holman
304
140k
Side Projects
sachag
451
41k
Building Effective Engineering Teams - LeadDev
addyosmani
28
1.8k
Large-scale JavaScript Application Architecture
addyosmani
504
110k
Building Adaptive Systems
keathley
31
1.9k
The Cost Of JavaScript in 2023
addyosmani
16
3.9k
Fashionably flexible responsive web design (full day workshop)
malarkey
398
65k
The Invisible Customer
myddelton
114
12k
Building Better People: How to give real-time feedback that sticks.
wjessup
355
18k
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