Skip to content

Latest commit

 

History

History
280 lines (217 loc) · 3.21 KB

File metadata and controls

280 lines (217 loc) · 3.21 KB

Endpoints :

List of available endpoints:

  • GET /random-words
  • POST /check-word
  • GET /rooms
  • POST /rooms
  • POST /rooms/:roomId/join
  • PUT /rooms/:roomId
  • GET /rooms/:roomId

1. GET /random-words

Response (200 - OK)

{
  "id": 81823,
  "word": "Reversion",
  "shortWord": "Rev"
}

 

2. POST /check-word

Request :

  • body :
{
  "question": "string",
  "answer": "string"
}

Response (200 - OK)

{
  "id": "integer",
  "word": "string"
}

Response (400 - Bad Request)

{
  "message": "You must answer according to the given words"
}

Response (404 - Error Not Found)

{
  "message": "Word Not Found"
}

 

3. GET /rooms

Response (200 - OK)

[
  {
    "id": "<string>",
     "name": "<string>",
    "winner": "<string>",
    "playerCount": "<integer>",
    "isFinished": "<boolean>",
    "Players": [
        {
        "id": "<integer>",
        "username": "<string>",
        "lives": "<integer>",
        "RoomId": "<integer>",
        "createdAt": "<string>",
        "updatedAt": "<string>"
      },
      ...
    ]
    ...
  }
]

 

4. POST /rooms

Request :

  • body :
{
  "name": "string",
  "username": "string"
}

Response (201 - CREATED)

{
  "message": "Room and player created!",
  "data": {
    "room": {
      "winner": "TBD",
      "playerCount": 1,
      "isFinished": false,
      "id": 8,
      "name": "string",
      "updatedAt": "string",
      "createdAt": "string"
    },
    "player": {
      "lives": 3,
      "id": 10,
      "RoomId": 8,
      "username": "string",
      "updatedAt": "string",
      "createdAt": "string"
    }
  }
}

Response (400 - Bad Request)

{
  "message": "Room not found"
}

Response (400 - Bad Request)

{
  "message": "Word Not Found"
}

 

5. POST /rooms/:roomId/join

Request :

  • params:
{
  "roomId": "<integer>"
}
  • body :
{
  "username": "string"
}

Response (201 - CREATED)

{
  "message": "Player joined room!",
  "player": {
    "lives": 3,
    "id": 10,
    "RoomId": 8,
    "username": "string",
    "updatedAt": "string",
    "createdAt": "string"
  }
}

Response (404 - Error Not Found)

{
  "message": "Room not found"
}

Response (400 - Bad Request)

{
  "message": "Sorry Room is full, please find another room"
}

 

6. PUT /rooms/:roomId

Request :

  • params:
{
  "roomId": "<integer>"
}

Response (200 - OK)

{
  "message": "Game has finished, thank you for playing"
}

 

7. GET /rooms/:roomId

Request :

  • params:
{
  "roomId": "<integer>"
}

Response (200 - OK)

{
    "id": 1,
    "name": "aku mau maen",
    "winner": "TBD",
    "playerCount": 2,
    "isFinished": false,
    "Players": [
        {
            "id": 1,
            "username": "nobueno_.",
            "lives": 3,
            "RoomId": 1
        },
        {
            "id": 3,
            "username": "nobueno",
            "lives": 3,
            "RoomId": 1
        }
    ]
}

 

Global Error

Response (500 - Internal Server Error)

{
  "message": "Internal server error"
}