Reputation:
I want to design an http route that sets a phone number as main for the current authenticated user.
could you suggest the proper http method and route to use.
I'm hesitating between GET /auth/phones/{phone_id}/main And PATCH /auth/phones/{phone_id} with object {main: true} in body request.
when setting a new main phone old main phone will automatically unset.
Upvotes: 2
Views: 4972
Reputation: 7106
Assuming /auth/phones/{phone_id}
represents a particular phone number of the authenticated user, I would do the following:
PATCH /auth/phones/{phone_id}
Content-Type: application/json
{
"main":true
}
HTTP method GET
should not be used to modifiy resource state.
Upvotes: 5
Reputation: 4184
Typically, you don't want to modify data via a GET method. The options you should be considering are POST/PUT/PATCH. A typical approach would be:
Upvotes: 1
Reputation: 536
According to Mozilla Foundation, PATCH is the correct way to apply partials updates to a record.
Read more in https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PATCH
Upvotes: 2