API
The API on Chipledger is the communication between the database and the frontend (and server rendered components). It is written in PHP, usually takes in GET parameters, and sends back JSON.
Table of Contents
Cheat Sheet
Here are all of the API endpoints that are available, in one master table.
Endpoint | Definition |
/api/auth/register | Registration api, creates new accounts, generates session ids. |
/api/auth/login | Login api, generates session ids. |
/api/auth/logout | Clears session ids. |
/api/data/releaseNotes | Returns HTML inside of JSON with all the Release Notes. |
/api/data/tutorial | Returns HTML inside of JSON with the tutorial page. |
/api/game/new | Creation of new games |
/api/game/delete | Deletion of games |
/api/game/list | Sends a JSON list of all available games |
/api/game/rename | Renames a game. |
/api/game/addPlayer | Adds a player to a game |
/api/game/addBuyin | Adds a buyin to a player in a game |
/api/game/addCashout | Adds a cashout to a player in a game |
/api/game/get | Gets all the current details of a game. |
/api/user/changePassword | Changes the users password. |
/api/user/changeEmail | Changes the users email. |
/api/user/delete | Deletes a users account. |
/api/user/get | Returns information on the users account. |
Authentication
Authentication endpoints include login, registration, and logouts.
Name | URL | GET | POST | COOKIE | Return Type | Return Contents |
Login | /api/auth/login | username , password |
JSON | username , session or error |
||
Register | /api/auth/register | username , email , password |
JSON | username , session or error |
||
Logout | /api/auth/logout | username , session |
Login and Register assign new session ids, and sets them inside of the database and the users cookies.
Logout is not to be used inside of the JS. It is rather used as a link to send when users logout. It headers the user to the homepage when completed. This is because not logged in users and authenticated users required different js scripts.
Data (Content)
These return content to fill pages. Donation has been removed.
Name | URL | GET | POST | COOKIE | Return Type | Return Contents |
Release Notes | /api/data/releaseNotes | JSON | data |
|||
Tutorial | /api/data/tutorial | JSON | data |
All of these endpoints return a data object which is a string full of HTML, and require no information or auth.
Game
All things related to current games for each user.
Name | URL | GET | POST | COOKIE | Return Type | Return Contents |
New | /api/game/new | name |
username , session |
JSON | data or error |
|
Delete | /api/game/delete | name |
username , session |
JSON | success or error |
|
List | /api/game/list | username , session |
JSON | Returns a list of all available games. Each item is the game name. | ||
Rename | /api/game/rename | oldname , newname |
username , session |
JSON | name or error |
|
Add Player | /api/game/addPlayer | name , playername |
username , session |
JSON | data or error |
|
Add Buyin | /api/game/addBuyin | name , playername , amount , method |
username , session |
JSON | data or error |
|
Add Cashout | /api/game/addCashout | name , playername , amount , method |
username , session |
JSON | data or error |
|
Edit Buyin | /api/game/editBuyin | name , playername , amount , method , buyinId |
username , session |
JSON | data or error |
|
Edit Cashout | /api/game/editCashout | name , playername , amount , method , cashoutId |
username , session |
JSON | data or error |
|
Get | /api/game/get | name |
username , session |
JSON | data or error |
The list endpoint returns a json list of all available games. It would look like this:
["gameName1","gameName2"]
Almost all of these endpoints return an updated version of the game. When a user acts upon an action, the JS sends a request at the endpoint, and if it recieves data, updates the dom.
The data endpoint is only used in rare circumstances, but returns what any action would without any modifications to the database.
Like other endpoints, the API call only succeeds if the cookies for the session and username are set and valid.
User
Slightly different than auth. Mostly relates to user settings and such.
Name | URL | GET | POST | COOKIE | Return Type | Return Contents |
Change Password | /api/user/changePassword | newpassword |
username , session |
JSON | success or error |
|
Change Email | /api/user/changeEmail | newemail |
username , session |
JSON | success or error |
|
Delete | /api/user/delete | name |
username , session |
JSON | success or error |
|
Get | /api/user/get | name |
username , session |
JSON | A list of details about the users account or error |
All of these are ran in browser, and no redirects should happen.
Delete will redirect the user through javascript, even though it may appear to be server side.