sriramrathinavelu / attendanceSWE2015

Attendance application for SWE 2015
1 stars 2 forks source link

Request for API - Register #61

Closed winddweb closed 8 years ago

winddweb commented 8 years ago

Now I the response I get after a successful registration is

User successfully added

I discussed with you that could you return the token for me so that I can save one request and use the token to update the user's other info directly?

winddweb commented 8 years ago

@sriramrathinavelu Hey Sriram, I need your opinion on this one. Furthermore, For registration response, I want you to include a flag of success/failure for me, along with the response message. This will make it easier to determine if the registration is successful.

// Now
"User successfully added"
// or
"User is already registered"

// wanted
{
  "status" : "success"
  "message" : "User successfully added"
}

// or 
{
  "status" : "failure"
  "message" : "User is already registered"
}

@TaniaSolo do you agree?

MahimaSrikanta commented 8 years ago

Hi All,

During my backend testing of Sriram's REST API code i had read some details about REST standard return codes. example: 2XX's(SUCCESS), 4XX's(Client Errors) Here is the link: http://www.restapitutorial.com/httpstatuscodes.html

It maybe useful to check for return codes than parsing return strings. Just attached the link above if it is useful to guys.

winddweb commented 8 years ago

Hey @MahimaSrikanta , thanks for the info.

Yeah if the Status code has a one to one relationship with the errors, I can use it. @sriramrathinavelu can you confirm this?

sriramrathinavelu commented 8 years ago

Hi @winddweb ,

Currently we have status code 200 for successful registration and 400 for erroneous/existing user registration and I have change register to return a token upon registration

(venv)teamsat_itu@instance-1:~/venv/attendanceSWE2015$ http --form POST http://localhost:8000/register/ email=test1@itu.edu password=password
HTTP/1.0 201 CREATED
Allow: POST, OPTIONS
Content-Type: application/json
Date: Fri, 04 Dec 2015 19:29:12 GMT
Server: WSGIServer/0.1 Python/2.7.3
Vary: Accept
X-Frame-Options: SAMEORIGIN
{
    "token": "9fd1e365b641a1c580ce9cb42e4d10d7c1b58ff785c2"
}
(venv)teamsat_itu@instance-1:~/venv/attendanceSWE2015$ http --form POST http://localhost:8000/register/ email=test1@itu.edu password=password
HTTP/1.0 400 BAD REQUEST
Allow: POST, OPTIONS
Content-Type: application/json
Date: Fri, 04 Dec 2015 19:31:12 GMT
Server: WSGIServer/0.1 Python/2.7.3
Vary: Accept
X-Frame-Options: SAMEORIGIN
"User is already registered."
sriramrathinavelu commented 8 years ago

Please not when user is registered HTTP status is 201 - 201 is successfully created and when user is existing the HTTP status is 400 - 400 is bad request.

Closing the issue. Please reopen if you face any issues