- /api/register "POST"
- Registers a new user to the database
- Takes an object with properties "username", "password"
- {username: "lorem", password: "lorem", birthdate: "Standard Date such as 'new Date()'" }
- all three are required
- /api/login "POST"
- Login existing user. Returns the web token.
- Takes an object with properties "username", "password"
* {username: "lorem", password: "lorem"}
- both are reqired
- Successful login returns web token
- Unsuccessful returns an object with the error in question
- /api/users "GET"
- Returns a list of all users
- JWT must be in the header under "authorize"
- Only accessible as admin
- /api/user/:id "GET"
- Returns user that matches the params: id * All the sleep data for that user is included an array of objects * { sleepData: [{}, {}] * }
- JWT must be in the header under "authorize"
- accessible by the user and admin
- /api/user/:id "PUT"
- Modifies user that matches the params: id
- Takes an object with the updated user values {id: , username: , password: }
- JWT must be in the header under "authorize"
- accessible by the user and admin
- On success returns the edited record
- checkpassword is required on the request.
* checks the password for authenticity before submitting the request
- { username: "example", password: "example", birthdate: "example", checkpassword: "current password of user" }
- if username, password, or birthdate aren't changed, they don't need to be included in the request.
- { birthdate: "example", checkpassword: "current password of user" }
- need to logout user after a username or password change
- /api/user/:id "DELETE"
- Deletes user that matches the params: id
- JWT must be in the header under "authorize"
- accessible by the user and admin
- On success returns the number of records deleted
- /api/sleepData "POST"
- Posts new sleep data to the DB
- Takes an object {userID: , start: ,end: ,hours: , scale}
* userID is required. Must match the user.
- start = start time
- end = end time
- hours = diffence of END and START
- scale = emoji value, currently set for 1 - 4
- JWT must be in the header under "authorize"
- accessible by the user and admin
- /api/sleepData/:id "PUT"
- Edits the recored matching the params: id
- Takes a sleep data object {userID: , start: ,end: , hours: , scale}
- JWT must be in the header under "authorize"
- accessible by the user and admin
- On success returns number of edited records
- /api/sleepData/:id "DELETE"
- Deletes record that matches the params: id
- JWT must be in the header under "authorize"
- accessible by the user and admin
- On Success Returns the number of records deleted
-
const options = { headers: { authorize: "Returned Web Token" } }
-
const url = "https://sleeptrack.hero........"
-
axios.get(url, options).then(....)