First, I'd like to explain the meanings of Hierarchical REST API and Normalized REST API that I made up.
http://www.example.com/customers/12345/orders)customer contains an order)
http://www.example.com/customers/12345{
"name": "John Doe",
"orders": [{
"id": 1,
"price": 10,
"delivered": true
}, {
"id": 2,
"price": 11,
"delivered": false
}
]
}
http://www.example.com/customers/12345/ordershttp://www.example.com/customers/12345/orders/1http://www.example.com/customers/12345/orders?accepted=truehttp://www.example.com/customershttp://www.example.com/customers?firstName=Johnhttp://www.example.com/customers/12345http://www.example.com/orders/1http://www.example.com/customers/12345{
"name": "John Doe",
"orderIds": [1, 2]
}
I think both methods have their own merits and drawbacks
http://www.example.com/customers/12345)http://www.example.com/customers/12345 and http://www.example.com/stores/1 can contain the same order data)orders from a certain customer, at least 2 requests are required from the client)My questions are:
Hierarchical REST API and Normalized REST API?Is there terminology for the Hierarchical REST API and Normalized REST API?
No.
Which one is more fit to the REST API guideline?
They are both "fine".
Consider the world wide web, and how we deliver CSS instructions to the browser. Can we embed CSS directly into an HTML page? Yes. Can we link to CSS that is fetched via a different resource? Yes.
Do both approaches "fit to the REST API guideline". Yes - more precisely, they work because HTML is a general-purpose standardized media type, with rules about how references to CSS work; and those rules are understood by everyone the same way.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With