REST API - Tidify-App/tidify-backend GitHub Wiki
REST API
Session
POST /session -- create a new session.
- POST-DATA: user with identification, hashed password or facebook token.
- RETURNS: {sessionid: [the session id]} -- this sessionid needs to be stored
by frontend and passed in every subsequent request.
DELETE /session/?sessionid=sessionid -- deletes session.
Users
user_object = {
_id:
username: ,
email: ,
}
achievement_object = {
_id:
title: "Dishwasher Pro",
user_id: objectId,
timestamp: "2003-08-14 18:08:04",
image: "https://url.goes.here"
}
GET /users/?sessionid=sessionid
- get users
- RETURNS: {users: [user_object, user_object, ...]} -- Lists all users
array of user_object.
GET /users/:id?sessionid=sessionid
- get user by given id
- RETURNS: {user: user_object} -- json object for user given by id.
PUT /users/:id?sessionid=sessionid
- update user by given id.
- PUT-DATA: {user: user_object} -- the user object to use for update.
- RETURNS: {success: true/false}.
DELETE /users/:id?sessionid=sessionid
- delete user by given id.
- RETURNS: {success: true/false}.
GET /users/:id/achievements?sessionid=sessionid
- get achievements by given user id
- RETURNS: {achievments: [achievement_object, achievement_object, ...]}
Tasks
task_object = {
_id:
name: ,
codename: ,
points: ,
imageurl: , // points to /taskimages/[codename]
}
GET /tasks/?sessionid=sessionid
- Lists all tasks
- RETURNS: {tasks: [task_object, task_object, ...]}
GET /tasks/:id?sessionid=sessionid
- get task json object for given by id.
- RETURNS: {task: task_object}
PUT /tasks/:id?sessionid=sessionid
- update task json object.
- PUT-DATA: {task: task_object} -- the task object to use for update.
- RETURNS: {success: true/false}.
DELETE /tasks/:id?sessionid=sessionid
- delete task by given id.
- RETURNS: {success: true/false}.
Task Images
GET /taskimages/:codename
- returns image by given task codename
- RETURNS: image
Game
{
game_object = {
"users": [user_id, user_id, ...],
"group_name": "group name";
"activities": [activity_object, activity_object, ...],
"achievements": [achievement_object, achievement_object, ...]
}
}
Activities
{
activity_object = {
"user_id": user_id,
"timestamp": "datetime",
"task": task_object
}
}
The following functions, get the current game from the users session id.
GET /activities?sessionid=sessionid
- Lists all activities for the current game, current game is determined by user's session_id.
- RETURNS: {activities: [activity_object, activity_object, ...]}
POST /activities?sessionid=sessionid
- Make new activity the current game, current game is determined by user's session_id.
- POST-DATA: {"activity": {"task": task_object}}
- RETURNS: {success: true/false}.
Websocket notices
When a new activity is created, a message about this is sent to clients over websockets. The notice has the following format.
{
"event": "new_activity",
"data": {
"user": {
"_id": "5b001d93281071643d74867e",
"name": "Test User 1",
"username": "user1",
"email": "[email protected]"
},
"task_codename": "testtask",
"points": 123
}
}
Score Board
// GET /scoreboard/?sessionid=sessionid
// ------ //
// 200 OK
// Content-Type: application/json
{
"group_name": "Le Residence",
"users": [
{
"name": "Firstname Lastname",
"username": "user1",
"current_score": 3250,
"image": "https://url.goes.here"
}
],
"latest_achievements": [
{
"title": "Dishwasher Pro",
"message": "user1 has logged Dishwashing five times!",
"user": user_object1,
"timestamp": "2003-08-14 18:08:04",
"image": "https://url.goes.here"
}
]
}