This file contains a list of the API endpoints that the server should respond to once it is completed. Use this as a guide if you aren't sure when specific functions should error or if you want more guidance for this assignment.
Before you read this, we encourage you to read over api/api.go and try to guess what the HTTP method for each function should be and why. Also think of any errors that could occur with the request. Once you do, come back and try to reason why we chose the specific HTTP methods for each endpoint.
- An empty response is an HTTP response with an empty body. It still has a status code. UPDATE 4/11 We are also allowing an empty response to contain a newline character in the body.
- An invalid JSON for an endpoint is a JSON that has bad syntax or at least one of the required keys for the endpoint has a value of the empty string when unmarshalled by Go. A JSON is not invalid if it has more keys than required by the endpoint (I.E. if an endpoint needs only needs a
usernameand the request has a JSON with ausernameandpassword, the JSON is valid). For all endpoints that require a JSON, if the given JSON is invalid or there is no JSON in the request, return an empty response with400 Bad Request.
| API Endpoint | HTTP Method | Description | Post Conditions |
|---|---|---|---|
/api/getCookie |
GET |
Echoes back the value of the access_token cookie if it exists. If it does not an empty response is returned. |
All GET requests to this endpoint should be responded to with status code 200 OK. |
/api/getQuery |
GET |
Echoes back the value of the URL parameter userID if it exists. If it does not, an empty response is returned. |
Same as above. |
/api/getJSON |
GET |
Given a JSON containing a username and password key, returns a response with the values in username and password separated by a newline. |
On success, the status code should be 200 OK. |
/api/signup |
POST |
Given a JSON containing a username and password, decrypts the JSON into a Credentials struct and adds it to the end of the global slice of users. |
If a user with the same username already exists in the slice, return an empty response with status code 409 Conflict. On success, the status code should be 201 Status Created. |
/api/getIndex |
GET |
Given a JSON containing a username, returns the index of the user in the global slice. |
If there does not exist a Credentials struct with the given username in the global slice, return an empty response with 400 Bad Request as the status code. On success, the status code should be 200 OK. |
/api/getPW |
GET |
Given a JSON containing a username, returns the password of the user. |
Same as above. |
/api/updatePW |
PUT |
Given a JSON containing a username and password, updates the password of the user with the given username to password. |
Same as above. |
/api/deleteUser |
DELETE |
Given a JSON containing a username, removes the Credentials of the user with that username from the global slice. |
Same as above. |