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
REST my dongle #kreait-dev-days
Search
Armen Mkrtchyan
June 05, 2015
Programming
140
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
REST my dongle #kreait-dev-days
REST best practices, HAL, HATEOAS
Armen Mkrtchyan
June 05, 2015
More Decks by Armen Mkrtchyan
See All by Armen Mkrtchyan
Api Protection
iamtankist
2
470
Life on the edge between AngularJS and Symfony2
iamtankist
9
3.8k
Other Decks in Programming
See All in Programming
ソフトウェア設計に溶けるインフラ ― AWS CDK のインフラ認識論
konokenj
3
770
torikago - Ruby::Boxで照らすモジュラモノリスの実行境界
se4weed
1
350
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
550
jsmini JavaScript Engine を作ってみた話
yosuke_furukawa
PRO
0
300
ルールを書いて終わらせないハーネスエンジニアリング
yug1224
4
1.9k
<title><a id="</title>君はこのHTMLをパースできるか"></a></title> #雑LT_study
pizzacat83
0
140
Lean は証明の正しさを確認するためだけのツールって思ってませんか?
inoueasei
1
150
為什麼你並不需要ViewModel / No, you don't need a ViewModel
lovee
1
480
What's New in Android 2026
veronikapj
0
250
メールのエイリアス機能を履き違えない
isshinfunada
0
230
Claude CodeとAgentCore Gatewayを繋ぐ際の認証認可 / Authentication and authorization when connecting Claude Code with AgentCore Gateway
har1101
2
260
AWS CDK を「作」ってみた 〜フルスクラッチで見えた CDK の裏側〜 / aws-cdk-from-scratch
gotok365
3
2.8k
Featured
See All Featured
jQuery: Nuts, Bolts and Bling
dougneiner
66
8.5k
What does AI have to do with Human Rights?
axbom
PRO
1
2.3k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.2k
Amusing Abliteration
ianozsvald
1
240
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
2
250
WCS-LA-2024
lcolladotor
0
790
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
2.9k
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
66
57k
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
170
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
4.3k
[RailsConf 2023] Rails as a piece of cake
palkan
59
6.9k
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.5k
Transcript
Logitech R400
Slide 1
Slide 2
GET /slides
[ { "id": 1, "content": "Slide 1" }, { "id":
2, "content": "Slide 2" }, ]
GET /slide/1
{ "id": 1, "content": "Slide 1", "background": "white", "text": "#031337"
}
Verb Method GET /slides Get list of slides C POST
/slides Create new slide R GET /slides/:id Get specific slide U PUT /slides/:id Update slide D DELETE /slides/:id Delete slide
Next Previous
None
1. GET /slides 2. Remember IDs 3. Figure out index
4. index++ 5. GET /slides/2
GET /slides/1/next GET /nextSlide/1
REST Maturity Model
HATEOAS (Hypertext As The Engine Of Application State) Level 3:
Hypermedia HAL (Hypertext Application Language)
{ "id": 5, "content": "Slide 1", "background": "white", "text": "#031337"
"_links": { "self": { "href": "/slides/5" }, "prev": { "href": "/slides/4" }, "next": { "href": "/slides/6" }, "first": { "href": "/slides/1" }, "last": { "href": "/slides/12" } } }
HAL + JSON http://stateless.co/hal_specification.html
R(B)EST practices
1. Do not use verbs /getAllSlides /createNewSlide /deleteAllBlackSlides GET /slides
POST /slides DELETE /slides?filter=black
2. GET method should NEVER alter the state GET /slide/1?action=disable
POST /slides/1/disable or PUT /slides/1/disable
3. Use plural nouns /slide /slides
4. Use sub-resources for relations GET /animationsForSlide/1 DELETE /animationsFromSlide/1/2 GET
/slides/1/animations/ DELETE /slides/1/animations/3
5. Use HTTP headers for serialization formats Content-type: application/vnd+com.kreait.slide+json
6. Use HAL { "id": 1, "content": "Slide 1", "background":
"white", "text": "#031337" "_links": { "self": { "href": "/slides/1" }, "next": { "href": "/slides/2" } } }
7. Filtering, Sorting, field selection and paging Filter GET /slides?background=white
Sort GET /slides?sort=-title,+length Limit Fields GET /slides?fields=id,title Pagination GET /slides?offset=10&limit=5
8. Version your API In URL: /api/v1/slides
9. Handle Errors with HTTP status codes http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html and https://github.com/joho/7XX-rfc
Errors in vnd.error format (https://github.com/blongden/vnd.error) or at least something consistent
10. Allow overriding HTTP method X-HTTP-Method-Override: PUT
Dongle included Thanks!