[geektalk#2] takaaki mizuno - api url design
TRANSCRIPT
![Page 1: [GeekTalk#2] Takaaki Mizuno - Api Url Design](https://reader038.vdocuments.site/reader038/viewer/2022100802/5877d94e1a28abaa6c8b5dab/html5/thumbnails/1.jpg)
DESIGING URLS OF WEB APITAKAAKI MIZUNO
![Page 2: [GeekTalk#2] Takaaki Mizuno - Api Url Design](https://reader038.vdocuments.site/reader038/viewer/2022100802/5877d94e1a28abaa6c8b5dab/html5/thumbnails/2.jpg)
DESIGNING URLS OF WEB API
I hesitate to use “REST” APIs today,
so just say “JSON over HTTP”
![Page 3: [GeekTalk#2] Takaaki Mizuno - Api Url Design](https://reader038.vdocuments.site/reader038/viewer/2022100802/5877d94e1a28abaa6c8b5dab/html5/thumbnails/3.jpg)
DESIGNING URLS OF WEB API
BECAUSE I VIOLATE MANY REST PRINCIPLES WHEN I DESIGN URL OF WEB API ;(
▸ Because we cannot follow REST architecture strictly sometimes.
▸ We can use many REST concept, but sometimes choose more practical solutions.
▸ REST is really misconceived concept
▸ Roy Fielding created this word in 2000
▸ REST is the architecture that described in his article
▸ Roy Fielding also said that “I am getting frustrated by the number of people calling any HTTP-based interface a REST API.” in 2008
![Page 4: [GeekTalk#2] Takaaki Mizuno - Api Url Design](https://reader038.vdocuments.site/reader038/viewer/2022100802/5877d94e1a28abaa6c8b5dab/html5/thumbnails/4.jpg)
DESIGING URLS OF WEB APITAKAAKI MIZUNO
PRACTICAL
![Page 5: [GeekTalk#2] Takaaki Mizuno - Api Url Design](https://reader038.vdocuments.site/reader038/viewer/2022100802/5877d94e1a28abaa6c8b5dab/html5/thumbnails/5.jpg)
テキスト
SUMMARY
I will explain some basic URL design rules
![Page 6: [GeekTalk#2] Takaaki Mizuno - Api Url Design](https://reader038.vdocuments.site/reader038/viewer/2022100802/5877d94e1a28abaa6c8b5dab/html5/thumbnails/6.jpg)
DESIGNING URLS OF WEB API
NEVER INCLUDE SERVER SIDE ARCHITECTURE
▸ Good
▸ http://api.example.com/users/100
▸ Bad
▸ http://api.example.com/cgi-bin/get_user.php?user=100
![Page 7: [GeekTalk#2] Takaaki Mizuno - Api Url Design](https://reader038.vdocuments.site/reader038/viewer/2022100802/5877d94e1a28abaa6c8b5dab/html5/thumbnails/7.jpg)
DESIGNING URLS OF WEB API
YOU USE NOUN ( PLURAL FORM ) FOR URLS
▸ Good
▸ https://api.example.com/v1/companies/12345
▸ Bad
▸ https://api.example.com/v1/company/12345
▸ https://api.example.com/v1/get-companies/12345
![Page 8: [GeekTalk#2] Takaaki Mizuno - Api Url Design](https://reader038.vdocuments.site/reader038/viewer/2022100802/5877d94e1a28abaa6c8b5dab/html5/thumbnails/8.jpg)
DESIGNING URLS OF WEB API
YOU USE NOUN ( PLURAL FORM ) FOR URLS
▸ URLs “basically” points “Resource”
▸ Set of resources
▸ https://api.example.com/v1/companies
▸ Individual resource
▸ https://api.example.com/v1/companies/123
![Page 9: [GeekTalk#2] Takaaki Mizuno - Api Url Design](https://reader038.vdocuments.site/reader038/viewer/2022100802/5877d94e1a28abaa6c8b5dab/html5/thumbnails/9.jpg)
DESIGNING URLS OF WEB API
USE HTTP METHODS AS “VERBS”
GET Get data ( don’t change data )
POST Create new data & change the state of data
PUT Update data
PATCH Update a part of data
DELETE Delete data
![Page 10: [GeekTalk#2] Takaaki Mizuno - Api Url Design](https://reader038.vdocuments.site/reader038/viewer/2022100802/5877d94e1a28abaa6c8b5dab/html5/thumbnails/10.jpg)
DESIGNING URLS OF WEB API
USE ALIES LIKE “ME” OR “SELF” FOR AUTHENTICATED USER RESOURCE
▸ Use me/self for the resource for user himself/herself
▸ https://api.exmaple.com/v1/users/me
▸ https://api.exmaple.com/v1/users/1234
![Page 11: [GeekTalk#2] Takaaki Mizuno - Api Url Design](https://reader038.vdocuments.site/reader038/viewer/2022100802/5877d94e1a28abaa6c8b5dab/html5/thumbnails/11.jpg)
DESIGNING URLS OF WEB API
VERSIONING
▸ Embed Major version of “semantic versioning” into URLs.
▸ https://api.example.com/v1/users/12345
▸ Violate REST concept, but practical
▸ Other Ways
▸ Use query params
▸ https://api.example.com/users/12345?v=20161010
▸ Behavior is not clear if client calls without params
▸ Use HTTP Request headers
▸ Accept: application/vnd.example.v2+json
▸ It’s most beautiful and following HTTP concept, but not common
![Page 12: [GeekTalk#2] Takaaki Mizuno - Api Url Design](https://reader038.vdocuments.site/reader038/viewer/2022100802/5877d94e1a28abaa6c8b5dab/html5/thumbnails/12.jpg)
テキスト
VERSIONING
▸ Semantic Versioning
▸ http://semver.org/
Ver. 1. 5. 7Major Minor Patch
NEED TO HAVE BACKWARD
COMPATIBILITY
BRAKING CHANGE
![Page 13: [GeekTalk#2] Takaaki Mizuno - Api Url Design](https://reader038.vdocuments.site/reader038/viewer/2022100802/5877d94e1a28abaa6c8b5dab/html5/thumbnails/13.jpg)
DESIGNING URLS OF WEB API
SPECIFYING DATA FORMAT
▸ Use query params
▸ https://api.example.com/v1/users?format=xml
▸ Practical, easy to understand, and format is not a resource
▸ Use extension
▸ https://api.example.com/v1/users.xml
▸ Okay, but format is not a resource
▸ Use HTTP Request header
▸ Accept: application/json
▸ I like most, and it’s okay for mobile apps.
▸ But not recommend to use for public APIs.
![Page 14: [GeekTalk#2] Takaaki Mizuno - Api Url Design](https://reader038.vdocuments.site/reader038/viewer/2022100802/5877d94e1a28abaa6c8b5dab/html5/thumbnails/14.jpg)
DESIGNING URLS OF WEB API
API Design is reviewed by other developers
![Page 15: [GeekTalk#2] Takaaki Mizuno - Api Url Design](https://reader038.vdocuments.site/reader038/viewer/2022100802/5877d94e1a28abaa6c8b5dab/html5/thumbnails/15.jpg)
DESIGNING URLS OF WEB API
Cool URLs make your service more cool