API for Routine app
- Currently running on: https://stark-peak-45925.herokuapp.com/
- Node js and NPM
- To get started run
npm startto kick off the server. Nodemon will reload the server on every save. - Run
gulp lintto lint the code or to keep it running the whole time rungulp watchin a separate terminal window - Before submitting a pull request run
npm run buildto ensure it will build correctly. Then runnpm run serveto ensure it will run correctly.
Routes in the User Registration section are authenticated by Username/Password unless otherwise mentioned.
Routes elsewhere in the app are authenticated by passing an 'X-Access-Token' header along with the request.
Route: POST api/users
Params:
| Parameter | Type |
|---|---|
| Password | String |
| Name | String |
| Username | String |
| String |
Note that usernames must be unique
Example success (Code 201 - Created):
{
"message": "User Created!"
}Example Failure (500 - Internal Server Error):
{
"errorMessage": "A user with that username already exists."
}Route: POST api/users/login
Params:
| Parameter | Type |
|---|---|
| Username | String |
| Password | String |
Example Success (Code 200 - OK)
{
"success": true,
"message": "Enjoy your token!",
"token" : "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJuYW1lIjoibmF0ZSIsInVzZXJuYW1lIjoibmF0ZSIsImlhdCI6MTQ0NDg1MTcxNSwiZXhwIjoxNDQ0OTM4MTE1fQ.9kOJEZb_f7HZ8RgmqbPwhDXALx2TDR1fH5lzPtlGzcA",
"id" : "5689545f46d5abacd7462d6e"
}Example Failure (Code 403 - Forbidden)
{
"errorMessage": "Password was incorrect."
}Or
(Code 404 - Not found)
{
"message": "Could not find user."
}#####Getting a Single User
Route: GET api/users/:user_id
####Editing an Existing User
Route: PUT api/users/:user_id
Params:
| Parameter | Type |
|---|---|
| Password | String |
| Name | String |
| Username | String |
Example Success (Code 200 -OK):
{
"message" : "User updated"
}####Deleting an Existing User
Route: DELETE api/users/:user_id
Params: None.
Example Success (Code 200 -OK):
{
"message" : "Successfully Deleted"
}Route: POST api/routines
Params:
| Parameter | Type |
|---|---|
| name | String |
| style | String |
| desiredFrequency | Number |
| startDate | unixTimestamp |
If 4-day is listed as a style the desiredFrequency will default to 4.
Example Success (Code 200 -OK):
{
"message": "routine created!",
"routine": {
"__v": 0,
"userId": "56d7baa3db2a93c7fbde4283",
"modifiedDate": 1457040918187,
"createdDate": 1457040918186,
"startDate": 1457040839535,
"desiredFrequency": 4,
"style": "4-day",
"name": "workout",
"_id": "56d8ae16f85b1ca5134ee207"
}
}Route: GET api/routines
Gets routines for the given userId
Route: GET api/routines/:routine_Id
Gets single routine
Route: api/routines/:routine_Id/
PUT updates given routine, if value is passed up it will be updated
DELETE deletes given routine
Route: POST api/routines/:routine_Id/subRoutines
Params: Same as creating a routine
If 4-day is listed as a style the desiredFrequency will default to 4.
Example Success (Code 200 -OK):
{
"message": "subRoutine created!",
"subRoutine": {
"__v": 0,
"userId": "56d7baa3db2a93c7fbde4283",
"modifiedDate": 1457041695726,
"createdDate": 1457041695725,
"routineId": "56d8ae88043411cb13bfc7b4",
"desiredFrequency": 4,
"style": "4-day",
"name": "bench press",
"_id": "56d8b11fbb2d6424146418d7"
}
}Route: GET api/routines/:routine_Id/subRoutines
Gets subRoutines for the given routine id
Route: GET api/routines/:routine_Id/subRoutines/:subRoutine_Id
Gets single subRoutine
Route: api/routines/:routine_Id/subRoutines/:subRoutine_Id
PUT updates given subRoutine, if value is passed up it will be updated
DELETE deletes given subRoutine
Route: POST api/routines/:routine_Id/days
Params:
| Parameter | Type |
|---|---|
| value | Number |
| date | unixTimestamp |
{
"message": "day created!",
"day": {
"__v": 0,
"userId": "56d7baa3db2a93c7fbde4283",
"routineId": "56d8ae88043411cb13bfc7b4",
"value": 2,
"date": 1457040839535,
"_id": "56d8b46f4e5df96914bbe9eb"
}
}Route: POST api/routines/:routine_Id/subRoutines/:subRoutine_Id/days
Params:
| Parameter | Type |
|---|---|
| value | Number |
| date | unixTimestamp |
{
"message": "day created!",
"day": {
"__v": 0,
"userId": "56d7baa3db2a93c7fbde4283",
"subRoutineId": "56d8b10abb2d6424146418d6",
"routineId": "56d8ae88043411cb13bfc7b4",
"value": 2,
"date": 1457040839535,
"_id": "56d8b44f4e5df96914bbe9ea"
}
}Route: GET api/routines/:routine_Id/days
Gets days for the given routine id
Route: GET api/routines/:routine_Id/subRoutines/:subRoutine_Id/days
Gets days for subroutine
Route: GET api/days/:day_id
Gets day
Route: api/days/:day_id
PUT updates given day, if value is passed up it will be updated
DELETE deletes given day
api/routines/:routine_Id/sevenDayMovingAverage
api/routines/:routine_Id/monthlyAverage
api/routines/:routine_Id/yearAverage
(same at subRoutine level)