F
F
foobarsik2019-07-04 04:24:34
RESTful API
foobarsik, 2019-07-04 04:24:34

Which endpoint to choose for a singleton resource (RESTish API)?

A user has only one business card page, a page can have only one button.
Possible endpoint options for editing a page button:
1. /pages/{id}/buttons/{id} (I would not like to use just /buttons/{id} because there are several modules, in order to avoid conflicts, suddenly in other modules too there will be some buttons)
2. /page/button
3. for each module its own api uri in the format site.com/api/page/v1, and the endpoint for the button will then be /button
4. /pages/my/button
First option good with a margin for the future, in case the customer decides to add the ability to create multiple pages and add multiple buttons to the page, but at the moment it looks redundant and adds unnecessary hassle.
What would you choose?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Spirin, 2019-07-04
@foobarsik

Does the button work with user data? If yes, then:

POST '/api/v1/profile/'

body: {
  name: 'UserName',
  /* other data */
  contactLink: 'mailto:[email protected]',
}

For an existing PATCH profile on the same path so that only changed data can be sent.
If the button does not work with data and can be deactivated, then by analogy with 'profile' we create some . Making endpoints to change individual buttons, IMHO, is insanity. POST '/api/v1/pages/{page_id}/content/'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question