D
D
dblearn942020-09-09 08:50:42
RESTful API
dblearn94, 2020-09-09 08:50:42

Correct formation of REST endpoints?

There are 3 resources:
1. Category - Category
2. Device - Belongs to category
3. Article - Belongs to device

How to properly organize EndPoints for Device, Article?
Nested

  • GET categories/:slug/devices
  • POST categories/:slug/devices
  • PUT categories/:slug/devices/:slugDevice


Or flat:
  • GET /categories/:slug/devices
  • GET /devices/?categoryId=1 (Alias ​​for item above)
  • POST /devices (categoryId passed in body)
  • PUT /devices/:slug


Are there any standards or amenities from one of the options?
I like the second option better because it's flat and easier to work with

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dr. Bacon, 2020-09-09
@dblearn94

If slugDevice is unique only within a category, then you will have to do "nested". Another minus of "nested" ones, in addition to your own identifier, you also need to know the nesting identifier, and what to do when it has changed, for example, moved to another category?
So I'm always for "flat", except when you need additional data for identification.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question