I have an object hierarchy that I want to expose through a REST API, and I want to discuss best practices. I have seen this question asked before (e.g. here at the end, here, here, and especially here), but never really any conclusions arrived at.
Suppose I have one base class, say Animal, and many different classes that inherit, say Antelope, Bird, ..., Zebra. Each kind of animal has unique attributes.
Which is better?
- One endpoint path,
/animals. You send and receive slightly different bodies depending on kind. There is atypefield to help parse. - A separate endpoint path for each kind of animal,
/animals/antelopes,/animals/birds, ...,/animals/zebras. Each endpoint would always accept and return a consistent body (but these bodies would be different from each other).