S8 Slides
S8 Slides
S8 Slides
Memi Lavi
www.memilavi.com
URL Structure
URL
Method
Headers
URL Structure
• Should be:
• Self explanatory
• Predictable
The Domain Name
server name
FQDN
The Domain Name
• Ie. https://api.myapp.com
The API Word
• Ie. https://www.myapp.com/api
• Positive
• No decimals
• Ie. https://www.myapp.com/api/v1
Entity
• NEVER a verb
• /api/v1/order
• /api/v2/employees
• /api/v2/travel
ID Parameter
• /api/v1/order/17
ID Parameter
• Relevant for:
• GET
• PUT
• DELETE
entities
• Common mistake:
• /api/v1/ItemsInOrder/17
• Not readable
• Not simple
Sub Entity
• /api/v1/order/17/items
• /api/v1/orders?fromDate=12/12/2018&toDate=2/2/2019
Query Parameters vs ID Parameter
Location
Param count
Example
Return value
If not found
Query Parameters vs ID Parameter
Param count
Example
Return value
If not found
Query Parameters vs ID Parameter
Example
Return value
If not found
Query Parameters vs ID Parameter
Return value
If not found
Query Parameters vs ID Parameter
Return value May return 0…N entities Must return exactly 1 entity
If not found
Query Parameters vs ID Parameter
Return value May return 0…N entities Must return exactly 1 entity
• The dilemma:
• /api/v1/order/17
• Or…
• /api/v1/orders/17
Singular vs Plural
• /api/v1/order?user=john
• Or…
• /api/v1/orders?user=john
Singular vs Plural
• No concrete answer
API
Word Entity Sub Entity
/api/v1/order/17/items?user=john&date=12/12/2018
Version ID Query Parameters
Param