Skip to content

Instantly share code, notes, and snippets.

@lucassha
Created December 3, 2018 03:09
Show Gist options
  • Save lucassha/45d9d1ee911ea3c2c813f92ae92d4310 to your computer and use it in GitHub Desktop.
Save lucassha/45d9d1ee911ea3c2c813f92ae92d4310 to your computer and use it in GitHub Desktop.

CS493 Final Project Documentation

Users, Teams, Players

  • 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

Response Codes

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

Schemas

User - id, username, password

Team - id, name, league, city, player, owner

Player - id, name, age, number, team


URL

/users

Request

GET

Parameters

Response

Status: 200 OK

JSON Response

{
    "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"
        }
    ]
}

URL

/users/signup

Request

POST

Parameters

  • Type: Body
  • Format: JSON
Name Type Descrip Required
username string Name of user Yes
password string password for user (later hashed) Yes

Response

Status: 201 Created

JSON Response

{
    "message": "User successfully created",
    "_id": "5c049b0591b12c1a7cd7a9a2",
    "hashed_pw": "$2b$10$OYZLDscEaxqOikBLAVDgc.N5sqvd4ZA5VGU9FQ7zhLbTRJDB3VUie",
    "username": "user1",
    "self": "localhost:3000/users/5c049b0591b12c1a7cd7a9a2"
}


URL

/users/login

Request

POST

Parameters

  • Type: Body
  • Format: JSON
Name Type Descrip Required
username string Name of user Yes
password string password for user Yes

Response

Status: 200 OK

JSON Response

{
    "message": "Authentication successful",
    "jwt_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6InNoYW5ub24iLCJ1c2VySWQiOiI1YzA0OWIwNTkxYjEyYzFhN2NkN2E5YTIiLCJpYXQiOjE1NDM4MDU3NzAsImV4cCI6MTU0Mzg5MjE3MH0.iFKVUCSc9SkpToE9OIuMsq19YPgD9H2r1YL6vGqVETg"
}


URL

/users/{user id}

Request

GET

Parameters

Response

Status: 200 OK

JSON Response

{
    "_id": "5c049b0591b12c1a7cd7a9a2",
    "username": "user1"
}

URL

/users/{user id}

Request

PUT

Parameters

  • Type: Body
  • Format: JSON
Name Type Descrip Required
username string Name of user Yes
password string password for user (later hashed) Yes

Response

Status: 204 No Content

URL

/teams

Request

GET

Parameters

  • Type: Query String
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.

Response

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": []
        }
    ]
}

Request

POST

Parameters

  • Type: Body
  • Format: JSON
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

Response

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"
}



URL

/teams/{team_id}

Request

GET

Parameters

  • Type: URL
Name Type Descrip Required
team id string id of the ship Yes

Response

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)


Request

PATCH

Edit all fields except player and owner

Parameters

  • Type: URL
Name Type Descrip Required
team id string id of the team Yes
  • Type: Body

  • Format: JSON

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

Response

Status: 204 No Content

Request

DELETE

Parameters

  • Type: URL
Name Type Descrip Required
team id string id of the team Yes

Expected JSON Response Sample





URL

/teams/{team id}/players/{player id}

Request

PATCH

Parameters

  • Type: URL
Name Type Descrip Required
team id string id of the team Yes
player id string id of the player Yes

Response

Status: 204 No Content

Request

DELETE

Parameters

  • Type: URL
Name Type Descrip Required
team id string id of the team Yes
player id string id of the player Yes

Response

Status: 204 No Content



URL

/players

Request

GET

Parameters

  • Type: Query String
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.

Response

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": {}
        }
    ]
}

Request

POST

Parameters

  • Type: Body
  • Format: JSON
Name Type Descrip Required
number number Player number Yes
name string Player name Yes
age number Player age Yes

Response

Status: 201 Created

Expected JSON Response Sample

{
    "message": "Player successfully created",
    "id": "5c049c7491b12c1a7cd7a9aa",
    "name": "lebron",
    "number": 23,
    "age": 35,
    "self": "localhost:3000/players/5c049c7491b12c1a7cd7a9aa"
}



URL

/player/{player id}

Request

GET

Parameters

  • Type: URL
Name Type Descrip Required
player id string id of the player Yes

Response

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"
}

Request

PATCH

Parameters

  • Type: URL
Name Type Descrip Required
player id string id of the player Yes
  • Type: Body
  • Format: JSON
Name Type Descrip Required
number number Player number Yes
name string Player name Yes
age number Player age Yes

Response

Status: 204 No Content

Request

DELETE

Parameters

  • Type: URL
Name Type Descrip Required
player id string id of the player Yes

Response

Status: 204 No Content
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment