Sleep Tracker API Documentation
https://sleep-tracker-backend.herokuapp.com/
Requires an object containing the new users information
Returns a JSON object
{"message": "User successfully created"}
Parameters
Description
username
string , required , must be unique
email
string , required , must be unique
password
string , required
Requires an object containing the users information
Stores a cookie containing the jwt
Returns a JSON object including the jwt
{
token : "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE2MDAwMDgxNjh9.mO0jOjng0nHo8NUVCOBbhleshdcKBDB_KKMMgpeY1ZU" ,
message : `Welcome ${ username } !`
}
Parameters
Description
username
string , required , must be unique
password
string , required
Returns a status code 204 if logout successful
Requires a user to be logged in
Returns a JSON object containing logged in users information
{
"id" : "c0137caf-69db-4040-8fef-7490ff829d45" ,
"username" : "JohnDoe" ,
"email" : "email@email.com" ,
"recommended_hours" : 8 ,
"admin" : 1
}
Requires a user to be logged in
Requires at least one valid parameter to update in request body
Returns a status code 204 if update successful
Parameters
Description
admin
boolean , optional
username
string , optional
password
string , optional
Requires a user to be logged in
Returns a status code of 204 if delete user successful
Requires an admin user to be logged in
Returns an array containing all users information
{
"id" : "c0137caf-69db-4040-8fef-7490ff829d45" ,
"username" : "JohnDoe" ,
"email" : "email@email.com" ,
"recommended_hours" : 8 ,
"admin" : 1
}
Requires an admin user to be logged in
Requires a user Id
Returns a JSON object containing a users information by id
{
"id" : "c0137caf-69db-4040-8fef-7490ff829d45" ,
"username" : "JohnDoe" ,
"email" : "email@email.com" ,
"recommended_hours" : 8 ,
"admin" : 1
}
Requires an admin user to be logged in
Requires a user Id to delete
Returns a status code of 204 if delete user successful
creates a new sleep log for current day
Requires user to be logged in
Returns a JSON object containing newly created sleep log data
Parameters
Description
bedtime
string , required , format: "23:00:00"
{
"id" : "12b43ec0-3d08-4b6d-9cdd-94efabdc1d63" ,
"bedtime" : "23:00:00" ,
"date" : "2020-09-20T04:00:00.000Z" ,
"wake_time" : null ,
"total_hours_slept" : null ,
"average_quality" : 0
}
updates a sleep day log by day log id
Requires user to be logged in
Requires a valid sleep log id for endpoint :id
Returns a JSON object containing updated sleep log data
Parameters
Description
wake_time
string , required , format: "06:00:00"
wake_score
integer (between 1-4) , optional
day_score
integer (between 1-4) , optional
bedtime_score
integer (between 1-4) , optional
{
"id" : "12b43ec0-3d08-4b6d-9cdd-94efabdc1d63" ,
"date" : "2020-09-20T04:00:00.000Z" ,
"bedtime" : "23:00:00" ,
"wake_time" : "06:00:00" ,
"total_hours_slept" : null ,
"average_quality" : 2 ,
"wake_score" : 2 ,
"day_score" : 1 ,
"bedtime_score" : 3 ,
"weekly_average_hours_slept" : 0 ,
"weekly_average_quality" : 0
}
Requires user to be logged in
Returns an array containing all sleep day logs for a user by user Id
ordered by newest first
[
{
"id" : "12b43ec0-3d08-4b6d-9cdd-94efabdc1d63" ,
"date" : "2020-09-20T04:00:00.000Z" ,
"bedtime" : "23:00:00" ,
"wake_time" : "06:00:00" ,
"total_hours_slept" : null ,
"average_quality" : 2 ,
"wake_score" : 2 ,
"day_score" : 1 ,
"bedtime_score" : 3
} ,
{
"id" : "8e9ab192-50bf-43fa-832a-f2139e664a8f" ,
"date" : "2020-08-30T04:00:00.000Z" ,
"bedtime" : "23:00:00" ,
"wake_time" : "06:00:00" ,
"total_hours_slept" : 7 ,
"average_quality" : 3 ,
"wake_score" : 3 ,
"day_score" : 3 ,
"bedtime_score" : 3
} ,
]
day/current-user/search/?date={date}
Requires user to be logged in
Requires a date string in the format 2020-08-20
Returns a JSON object containing sleep day log data for a user by
date query
{
"id" : "b1a07ba8-b5f9-4a84-9c49-39b70cd17e87" ,
"date" : "2020-08-20T04:00:00.000Z" ,
"bedtime" : "23:00:00" ,
"wake_time" : "06:00:00" ,
"total_hours_slept" : 7 ,
"average_quality" : 3 ,
"wake_score" : 3 ,
"day_score" : 3 ,
"bedtime_score" : 3
}
Requires user to be logged in
Requires a valid sleep log id for endpoint :id
Returns a status code of 204 if sleep day log deleted successfully
Requires user to be logged in
Returns an array containing all sleep week logs for a user by
user Id
ordered by date
[
{
"id" : "6023a295-69df-4f66-864d-b93fc6090fa7" ,
"week_of_year" : "39/2020" ,
"average_hours_slept" : 0 ,
"average_quality" : 0 ,
"users_id" : "655b3e68-2d9b-4041-a197-705b393baec1"
} ,
{
"id" : "f08ca2c0-2d5e-4598-b607-17d0d0397f08" ,
"week_of_year" : "36/2020" ,
"average_hours_slept" : 7 ,
"average_quality" : 3 ,
"users_id" : "655b3e68-2d9b-4041-a197-705b393baec1"
}
]
/week/current-user/search/?date={date}
Requires user to be logged in
Requires a date string in the format 8-19-2020
Returns a JSON object containing sleep week log data for a user by
date query
[
{
"id" : "13787c97-dae9-4438-864e-67346fdb19ee" ,
"week_of_year" : "34/2020" ,
"average_hours_slept" : 7 ,
"average_quality" : 3
}
]
Requires user to be logged in
Returns an array containing all sleep month logs for a user by
user Id
ordered by date
[
{
"id" : "16567638-4651-409c-9b39-66badd175e2d" ,
"month_of_year" : "8/2020" ,
"average_hours_slept" : 7 ,
"average_quality" : 3 ,
"users_id" : "655b3e68-2d9b-4041-a197-705b393baec1"
} ,
{
"id" : "35440c37-edfb-4026-8314-9bf866eff4d8" ,
"month_of_year" : "7/2020" ,
"average_hours_slept" : 7 ,
"average_quality" : 3 ,
"users_id" : "655b3e68-2d9b-4041-a197-705b393baec1"
}
]
month/current-user/average
Requires user to be logged in
Returns an object containing total sleep quality for all months
[
{
"qualityTotal" : 6 ,
"totalMonths" : 2 ,
"averageQuality" : 3
}
]
/month/current-user/search/?date={date}
Requires user to be logged in
Requires a date string in the format 09-19-2020
Returns a JSON object containing sleep month log data for a user by
date query
[
{
"id" : "16567638-4651-409c-9b39-66badd175e2d" ,
"month_of_year" : "8/2020" ,
"average_hours_slept" : 7 ,
"average_quality" : 3
}
]