Skip to content
Advertisement

what is the best way to register a new user – get vs post

i’m trying to learn best practices for registering new users.

I can only think of two options (but maybe there are more!) and am hoping to know which is better for speed, and for overall practice:

first method:

a. once the user submits a new user&pass, i make a GET request on a REST entrypoint
b. if the user exists then let him know, if not then make a POST request

second method:

a. once the user submits a new user&pass, i make a POST request, within which a GET request is made.
b. if the user exists then let him know, if not then continue with the POST

also, should these be done within one entry point – go back to the client, and then have js do another call

thanks

Advertisement

Answer

It’s better having only one POST request, that return a 409(conflict) status if the user already exists, and a 201(resource created) status if the user was successfully created.

Advertisement