L
L
lexstile2021-04-05 16:59:43
API
lexstile, 2021-04-05 16:59:43

How to get/add user data correctly?

How to make getting/adding user data more correct?
Example 1: we call the getUser method from the front - we get a 404 error and then from the front we pull the next method to create a user.
Example 2: or should there be a universal method, conditionally - callUser, which creates a record in the database and returns data - either after creation, if the user was absent, or immediately, if the user is already present in the database?!

Or is there a more beautiful and correct option?
How to organize this kind of interaction?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2021-04-05
@lexstile

There can be no getUser, callUser, etc. methods in REST.
There should be a users resource and requests to it using different HTTP methods.
GET https://example.com/users - gets all users
GET https://example.com/users/ivanov - gets user with login ivanov
POST https://example.com/users/ivanov - adds user with login ivanov
PUT https://example.com/users/ivanov - add or change user with login ivanov
PATH https://example.com/users/ivanov - change user with login ivanov
DELETE https://example.com/users/ivanov- deletes user with login ivanov

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question