CS493 Final Project Documentation
Users
/users - GET
/users/{user id} - PUT, DELETE
/users/signup - POST
/users/login - POST
Teams
/teams - GET, POST
/teams/{team id} - GET, PATCH, DELETE
/teams/{team id}/players/{player id} - PATCH, DELETE
Players
/players - GET, POST
/players/{player id} - GET, PATCH, DELETE
Status
Definition
200
OK
201
Created
204
No Content
401
Unauthorized
403
Forbidden
404
Not Found
405
Method Not Allowed
406
Not Acceptable
500
Server error
Headers
All requests must use Accept - application/json
User - id, username, password
Team - id, name, league, city, player, owner
Player - id, name, age, number, team
/users
GET
Status: 200 OK
{
"count": 2,
"users": [
{
"username": "user1",
"hashed_password": "$2b$10$OYZLDscEaxqOikBLAVDgc.N5sqvd4ZA5VGU9FQ7zhLbTRJDB3VUie",
"_id": "5c049b0591b12c1a7cd7a9a2",
"self": "localhost:3000/users/5c049b0591b12c1a7cd7a9a2"
},
{
"username": "caitlyn",
"hashed_password": "$2b$10$vYTCtkUd52ohiGSZGnmO1.fvqOhSD7Toumm797KLngDWqP2nvocsK",
"_id": "5c049b1f91b12c1a7cd7a9a3",
"self": "localhost:3000/users/5c049b1f91b12c1a7cd7a9a3"
}
]
}
/users/signup
POST
Name
Type
Descrip
Required
username
string
Name of user
Yes
password
string
password for user (later hashed)
Yes
Status: 201 Created
{
"message": "User successfully created",
"_id": "5c049b0591b12c1a7cd7a9a2",
"hashed_pw": "$2b$10$OYZLDscEaxqOikBLAVDgc.N5sqvd4ZA5VGU9FQ7zhLbTRJDB3VUie",
"username": "user1",
"self": "localhost:3000/users/5c049b0591b12c1a7cd7a9a2"
}
/users/login
POST
Name
Type
Descrip
Required
username
string
Name of user
Yes
password
string
password for user
Yes
Status: 200 OK
{
"message": "Authentication successful",
"jwt_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6InNoYW5ub24iLCJ1c2VySWQiOiI1YzA0OWIwNTkxYjEyYzFhN2NkN2E5YTIiLCJpYXQiOjE1NDM4MDU3NzAsImV4cCI6MTU0Mzg5MjE3MH0.iFKVUCSc9SkpToE9OIuMsq19YPgD9H2r1YL6vGqVETg"
}
/users/{user id}
GET
Status: 200 OK
{
"_id": "5c049b0591b12c1a7cd7a9a2",
"username": "user1"
}
/users/{user id}
PUT
Name
Type
Descrip
Required
username
string
Name of user
Yes
password
string
password for user (later hashed)
Yes
Status: 204 No Content
/teams
GET
Name
Type
Descrip
Required
page number
string
page number of responses
No
Regardless of passed in parameter, a maximum of 5 responses will be populated per page.
Status: 200 OK
Expected JSON Response Sample for Page 1
{
"total_results": 6,
"page": 1,
"pages": 2,
"results_per_page": 5,
"next_page": "localhost:3000/teams/?page=2",
"teams": [
{
"_id": "5c049b6991b12c1a7cd7a9a4",
"name": "blazers",
"league": "NBA",
"city": "portland",
"owner": "shannon",
"self": "localhost:3000/teams/5c049b6991b12c1a7cd7a9a4",
"players": []
},
{
"_id": "5c049c0991b12c1a7cd7a9a5",
"name": "suns",
"league": "NBA",
"city": "phoenix",
"owner": "shannon",
"self": "localhost:3000/teams/5c049c0991b12c1a7cd7a9a5",
"players": []
},
{
"_id": "5c049c0b91b12c1a7cd7a9a6",
"name": "hornets",
"league": "NBA",
"city": "charlotte",
"owner": "shannon",
"self": "localhost:3000/teams/5c049c0b91b12c1a7cd7a9a6",
"players": []
},
{
"_id": "5c049c0e91b12c1a7cd7a9a7",
"name": "spurs",
"league": "NBA",
"city": "san antonio",
"owner": "caitlyn",
"self": "localhost:3000/teams/5c049c0e91b12c1a7cd7a9a7",
"players": []
},
{
"_id": "5c049c1091b12c1a7cd7a9a8",
"name": "thunder",
"league": "NBA",
"city": "okalahoma city",
"owner": "caitlyn",
"self": "localhost:3000/teams/5c049c1091b12c1a7cd7a9a8",
"players": []
}
]
}
Expected JSON Response Sample for Page 2
{
"total_results": 6,
"page": "2",
"pages": 2,
"results_per_page": 5,
"next_page": "localhost:3000/teams/?page=3",
"teams": [
{
"_id": "5c049c1291b12c1a7cd7a9a9",
"name": "knicks",
"league": "NBA",
"city": "new york city",
"owner": "caitlyn",
"self": "localhost:3000/teams/5c049c1291b12c1a7cd7a9a9",
"players": []
}
]
}
POST
Name
Type
Descrip
Required
name
string
Name of the team
Yes
league
string
Team league
Yes
city
string
City where team is located
Yes
owner
string
Owner of the team (user)
Yes
player
[ string ]
Players on the team
Yes
Status: 201 Created
Expected JSON Response Sample
{
"message": "Team successfully created",
"id": "5c049b6991b12c1a7cd7a9a4",
"name": "blazers",
"league": "NBA",
"city": "portland",
"owner": "shannon",
"self": "localhost:3000/teams/5c049b6991b12c1a7cd7a9a4"
}
/teams/{team_id}
GET
Name
Type
Descrip
Required
team id
string
id of the ship
Yes
Status: 200 OK
Expected JSON Response Sample (with no players assigned team)
{
"_id": "5c049b6991b12c1a7cd7a9a4",
"name": "blazers",
"league": "NBA",
"city": "portland",
"owner": "shannon",
"root_url": "localhost:3000/teams",
"players": []
}
Expected JSON Response Sample (with players assigned to the team)
PATCH
Edit all fields except player
and owner
Name
Type
Descrip
Required
team id
string
id of the team
Yes
Name
Type
Descrip
Required
name
string
Name of the team
Yes
league
string
Team league
Yes
city
string
City where team is located
Yes
owner
string
Owner of the team (user)
Yes
Status: 204 No Content
DELETE
Name
Type
Descrip
Required
team id
string
id of the team
Yes
Expected JSON Response Sample
/teams/{team id}/players/{player id}
PATCH
Name
Type
Descrip
Required
team id
string
id of the team
Yes
player id
string
id of the player
Yes
Status: 204 No Content
DELETE
Name
Type
Descrip
Required
team id
string
id of the team
Yes
player id
string
id of the player
Yes
Status: 204 No Content
/players
GET
Name
Type
Descrip
Required
page number
string
page number of responses
No
Regardless of passed in parameter, a maximum of 5 responses will be populated per page.
Status: 200 OK
Expected JSON Response Sample for Page 1
{
"total_results": 6,
"page": 1,
"pages": 2,
"results_per_page": 5,
"next_page": "localhost:3000/teams/?page=2",
"players": [
{
"_id": "5c049c7491b12c1a7cd7a9aa",
"name": "lebron",
"number": 23,
"age": 35,
"self": "localhost:3000/players/5c049c7491b12c1a7cd7a9aa",
"team": {}
},
{
"_id": "5c049c8891b12c1a7cd7a9ab",
"name": "kemba",
"number": 1,
"age": 29,
"self": "localhost:3000/players/5c049c8891b12c1a7cd7a9ab",
"team": {}
},
{
"_id": "5c049c8b91b12c1a7cd7a9ac",
"name": "kobe",
"number": 6,
"age": 42,
"self": "localhost:3000/players/5c049c8b91b12c1a7cd7a9ac",
"team": {}
},
{
"_id": "5c049c8d91b12c1a7cd7a9ad",
"name": "shaq",
"number": 2,
"age": 45,
"self": "localhost:3000/players/5c049c8d91b12c1a7cd7a9ad",
"team": {}
},
{
"_id": "5c049c9191b12c1a7cd7a9ae",
"name": "duncan",
"number": 21,
"age": 42,
"self": "localhost:3000/players/5c049c9191b12c1a7cd7a9ae",
"team": {}
}
]
}
Expected JSON Response Sample for Page 2
{
"total_results": 6,
"page": "2",
"pages": 2,
"results_per_page": 5,
"next_page": "localhost:3000/teams/?page=3",
"players": [
{
"_id": "5c049c9491b12c1a7cd7a9af",
"name": "kawhi",
"number": 2,
"age": 27,
"self": "localhost:3000/players/5c049c9491b12c1a7cd7a9af",
"team": {}
}
]
}
POST
Name
Type
Descrip
Required
number
number
Player number
Yes
name
string
Player name
Yes
age
number
Player age
Yes
Status: 201 Created
Expected JSON Response Sample
{
"message": "Player successfully created",
"id": "5c049c7491b12c1a7cd7a9aa",
"name": "lebron",
"number": 23,
"age": 35,
"self": "localhost:3000/players/5c049c7491b12c1a7cd7a9aa"
}
/player/{player id}
GET
Name
Type
Descrip
Required
player id
string
id of the player
Yes
Status: 200 OK
Expected JSON Response Sample (if player is assigned to team)
{
"_id": "5c049c9491b12c1a7cd7a9af",
"name": "rick astley",
"number": 100,
"age": 52,
"team_name": "spurs",
"players_root_url": "localhost:3000/players",
"team_root_url": "localhost:3000/teams"
}
Expected JSON Response Sample (if player is NOT assigned to a team)
{
"_id": "5c049c7491b12c1a7cd7a9aa",
"name": "lebron",
"number": 23,
"age": 35,
"team_name": "",
"players_root_url": "localhost:3000/players",
"team_root_url": "localhost:3000/teams"
}
PATCH
Name
Type
Descrip
Required
player id
string
id of the player
Yes
Name
Type
Descrip
Required
number
number
Player number
Yes
name
string
Player name
Yes
age
number
Player age
Yes
Status: 204 No Content
DELETE
Name
Type
Descrip
Required
player id
string
id of the player
Yes
Status: 204 No Content