Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

REST: multiple ways of creating the same resource

Tags:

rest

If you are modelling a resource which can be created in multiple ways, how do you best deal with that?

I can imagine doing POST to the same resource with a query param differentiating the different ways, something like

POST /logins?type=pwd with body { email, pwd } -> CREATED /logins/1
POST /logins?type=token with body { token } -> CREATED /logins/2
like image 670
Alexander Torstling Avatar asked Nov 09 '22 22:11

Alexander Torstling


1 Answers

I think that a single POST /logins should be enough. It can be called with a payload containing {email, pwd} or {token} only. The implementation of this endpoint should decide in which case we are and how to create the resource after making the necessary validation on the body (email + pwd provided or token only provided).

like image 162
Darin Dimitrov Avatar answered Nov 15 '22 07:11

Darin Dimitrov