Connect4API

|   |   |   |   |   |   |   |
-----------------------------
|   |   |   |   |   |   |   |
-----------------------------
|   |   |   | X |   | O |   |
-----------------------------
|   |   | O | O | X | X |   |
-----------------------------
|   |   | X | X | O | O |   |
-----------------------------
|   | X | X | O | O | X | X |
-----------------------------

An API to play connect 4 from your terminal or web browser with a friend

Quick Tutorial

  • 1 : Grab a friend (or play with yourself) and create a session. This will return a session id to the client.

    https://connectfourapi.com/api/create
  • 2 : Open a second terminal (or tab if your are using a web browser) and connect to the session using the session id created in step 1. Both players should do this. This will broadcast live updates.

    https://connectfourapi.com/api/{sessionid}/connect
  • 3 : Both players can now join the session. You should be able to see live session changes within your connected client.

    https://connectfourapi.com/api/{sessionid}/{Player 1's name}/join
    https://connectfourapi.com/api/{sessionid}/{Player 2's name}/join
  • 4 : Once both players have joined the session, start the game.

    https://connectfourapi.com/api/{sessionid}/start
  • 5 : Once the game has started, the current turn player can drop a piece on a column of choice.

    https://connectfourapi.com/api/{sessionid}/{Current turn player's name}/{column}
API documentation

Main routes

Core API routes that are needed to play the game

Create a session
https://connectfourapi.com/api/create

Session will be created. Client receives a session ID used for the rest of the api calls.

Connect to a session
https://connectfourapi.com/api/{sessionid}/connect
Path Parameters:
  • {sessionid} : Session ID given from /api/create

Streaming endpoint to deliver live updates to the client over a long-lived HTTP connection. Both players should connect to their tables right after a session is created.

Join a session
https://connectfourapi.com/api/{sessionid}/{name}/join
Path Parameters:
  • {sessionid} : Session ID given from /api/create
  • {name} : 1-10 character name of your choosing

Join a session by giving a name. There can only be atmost 2 players in a session.

Start the game
https://connectfourapi.com/api/{sessionid}/start
Path Parameters:
  • {sessionid} : Session ID given from /api/{sessionid}/start

Start the game. Session must include 2 players.

Drop piece
https://connectfourapi.com/api/{sessionid}/{name}/{column}/drop
Path Parameters:
  • {sessionid} : Session ID given from /api/create
  • {name} : The name of the current player's turn
  • {column} : The column where you would want to drop your piece

Drop a piece on the board.

Misc Routes

Delete a session
https://connectfourapi.com/api/{sessionid}/delete
Path Parameters:
  • {sessionid} : Session ID given from /api/create

Delete a session. Not needed as session expires after an hour of inactivity.

Leave a table
https://connectfourapi.com/api/{sessionid}/{name}/leave
Path Parameters:
  • {sessionid} : Session ID given from /api/create
  • {name} : The name of the player that you want to leave

Leave a session. Can only call this route when the game has not started.