DEV Community

Discussion on: RESTful API design concerns

Collapse
 
sql_knievel profile image
Rich Boniface • Edited

We can all picture what a “car” represents, but what does a “spot” mean in this context? A physical parking spot? If so, think about the real relationship between them as entities. I’d argue that a car can exist without a spot (what if it’s out being driven and another car gets put in the previous spot?) and that a spot can exist without a car (the car that used to be in that spot got crashed, now what?)

If each one can exist in your system without the other, then I think there’s no real hierarchy between them and having both a /car/{carid} and a /spot/{spotid} endpoint makes more sense.

Collapse
 
herifauzan profile image
heri fauzan • Edited

Why don't use grapql instead.. You only need to design the query.. Not the endpoints..

Collapse
 
piczmar_0 profile image
Marcin Piczkowski

Sure, but my post refers to REST API, of course you can use different technologies where you don't have this problem, but sometimes you're constrained to use REST.

Collapse
 
piczmar_0 profile image
Marcin Piczkowski

Maybe I was not precise enough, please see my answer above.