Skip to content

API Doc

Alan Luo edited this page Sep 14, 2020 · 13 revisions

Table of Contents

Base URL

https://expanding-nim.iltc.app

Create Session

HTTP Request

POST /sessions.json

Parameters

Name Type Required Description
name String Yes Player A's name
stones Integer Yes Number of stones to start

Example Request

curl -H "Content-Type: application/json" \
     -d '{"name": "Alan", "stones": 100}' \
     -X POST "https://expanding-nim.iltc.app/sessions.json"

Successful Response

{
    "status": "success",
    "game_status": "wait_for_b_join",
    "session_id": 10,
    "token": "1436b2d1c6d981b693508da9ef78bd2d"
}

Notes

  • The player who creates a new session will always be the first player (Player A) in the game.
  • The token will only be shown once. If you lost it, you need to start a new session.

Join Session

HTTP Request

POST /sessions/join.json

Parameters

Name Type Required Description
id Integer Yes The id of the session that you want to join.
name String Yes Player B's name

Example Request

curl -H "Content-Type: application/json" \
     -d '{"id": 10, "name": "Bob"}' \
     -X POST "https://expanding-nim.iltc.app/sessions/join.json"

Successful Response

{
    "status": "success",
    "game_status": "wait_for_a_move",
    "session_id": 10,
    "token": "519c718c979c7b2fd2dbca26e2496735"
}

Session Status

HTTP Request

GET /sessions/[session-id]/status.json?token=[token]

Parameters

Name Type Required Description
session-id Integer Yes The id of the session that you want to check status.
token String Yes The token you received when creating or joining a session.

Example Request

curl -H "Content-Type: application/json" \
     -X GET "https://expanding-nim.iltc.app/sessions/10/status.json?token=519c718c979c7b2fd2dbca26e2496735"

Successful Response

If it is not your turn:

{
    "status": "success",
    "game_status": "wait_for_a_move",
    "your_turn": false,
    "message": "It's not your turn yet. Please wait for other player. Please don't refresh too frequently. Status: Wait for Player A's Move"
}

If it is your turn:

{
    "status": "success",
    "game_status": "wait_for_a_move",
    "your_turn": true,
    "message": "It's your turn now. Please make a move.",
    "stones_left": 100,
    "reset": false,
    "current_max": 0,
    "accept_max_value": 3,
    "reset_left": 4,
    "start_time": "2020-09-12T14:36:22.618Z",
    "time_left": 120
}

Notes

  • Please do not request this endpoint too frequently, as the backend server may think you are making a DDOS attack.
  • The clock will not start until you made a request to /sessions/[session-id]/status.json?token=[token] and receive your_turn = true.
  • For now, nothing will happen when time_left is 0 or negative. During the class, the game will end and the other player will win if you time_left reaches 0 first.

Make Move

HTTP Request

POST /sessions/[session-id]/move.json?token=[token]

Parameters

Name Type Required Location Description
session-id Integer Yes URL The id of the session that you want to check status.
token String Yes URL The token you received when creating or joining a session.
stones Integer Yes Body The number of stones you want to remove.
reset String No Body Whether or not you want to impose reset. Accept values are yes or no (default).

Example Request

curl -H "Content-Type: application/json" \
     -d '{"stones": 3, "reset": "no"}' \
     -X POST "https://expanding-nim.iltc.app/sessions/10/move.json?token=519c718c979c7b2fd2dbca26e2496735"

Successful Response

{
    "status": "success"
}

Notes

  • Please make sure you requested /sessions/[session-id]/status.json?token=[token] and received your_turn = true before requesting this endpoint. Otherwise, the clock will not function correctly.
  • For now, you can request this endpoint from anywhere (your laptop, linserv1, etc.). During the class, requests to this endpoint must come from linserv1, and other IPs will be blocked.