API Documentation¶
- GET /db¶
This is the backend service which populates the database with Users, Threads, Posts and the relations among them.
- Status Codes:
200 OK – no errors
- POST /login¶
Logs the user in by providing access and refresh tokens upon successful credentials check.
- Form Parameters:
username – registered username
password – registered password associated to username
- Status Codes:
200 OK – user is logged
400 Bad Request – missing username or password
401 Unauthorized – wrong username or password
- POST /register¶
Register a new user after some sanity checks. The user is still required to perform a POST to the /login endpoint to login.
- Form Parameters:
username – username not already present
password – password associated to new username
age – new user’s age
email – new user’s email
- Status Codes:
200 OK – user is registered
400 Bad Request – missing or unaccepted parameters
401 Unauthorized – underage user
409 Conflict – username already registered
500 Internal Server Error – problems with user insertion in database
- DELETE /logout¶
Logs the user out by storing the user’s token in the redis db which holds all revoked tokens.
- Status Codes:
200 OK – user logged out
- POST /refresh¶
Access tokens expires after 1h, in order to get a new one without logging in again the user can make a POST to this endpoint using the refresh token which instead expires after 24h.
- Status Codes:
200 OK – extended logged in session
- GET /whoami¶
Simple page to test the effectiveness of login/logout operations.
- Status Codes:
200 OK – no error
500 Internal Server Error – retrival of username produced more than one or no result
- GET /threads¶
This is the Threads Dashboard where the logged user can go through followed threads or recommended ones. The backend service captures a new Thread data and registers it.
- Status Codes:
200 OK – no error
500 Internal Server Error – problems retrieving threads collection
- POST /threads¶
This endpoint captures a new Thread data and registers it.
- Form Parameters:
title – thread title
text – thread text
creation date – thread date
- Status Codes:
200 OK – thread created
400 Bad Request – when title or text or date parameters are missing, when title is an empty string
500 Internal Server Error – problems with thread insertion in database
- GET /threads/(thread_id)¶
This is a specific Thread page in which information about it are reported as well as the related comments.
- Parameters:
thread_id (str) – thread’s unique id
- Status Codes:
200 OK – no error
404 Not Found – when thread id is not found
- GET /threads/(thread_id)/followers¶
This endpoints returns all users following a thread.
- Parameters:
thread_id (str) – thread’s unique id
- Status Codes:
200 OK – no error
500 Internal Server Error – problems with followers retrieval
- POST /threads/(thread_id)/followers¶
This endpoints adds the logged user to the list of the threads’ followers.
- Parameters:
thread_id (str) – thread’s unique id
- Status Codes:
200 OK – no error
500 Internal Server Error – problems with relationship insertion in database
- DELETE /threads/(thread_id)/followers¶
This endpoints removes the logged user from the list of the threads’ followers.
- Parameters:
thread_id (str) – thread’s unique id
- Status Codes:
200 OK – no error
500 Internal Server Error – problems with relationship deletion in database
- GET /posts/(post_id)¶
This is a specific Post page in which information about it are reported as well as the related replies.
- Parameters:
post_id (str) – post’s unique id
- Status Codes:
200 OK – no error
404 Not Found – when post id is not found
- POST /threads/(thread_id)/posts¶
This endpoint captures a new Post data and registers it.
- Form Parameters:
text – post text
date – post date
- Status Codes:
200 OK – post created
400 Bad Request – when text or date parameters are missing, when text is an empty string or when the thread is not found
- POST /posts/(post_id)/replies¶
This endpoint captures a new Reply data to a specific Post and registers it.
- Form Parameters:
text – post text
date – post date
- Status Codes:
200 OK – post created
400 Bad Request – when text or date parameters are missing, when text is an empty string or when parent post id not found
- PUT /posts/(post_id)¶
This endpoint captures a update Post data and saves it.
- Form Parameters:
text – post text
- Status Codes:
200 OK – post updated
400 Bad Request – when text is missing or empty
401 Unauthorized – when user is not logged in or try to edit others posts
404 Not Found – when post is not found
- GET /search¶
This is the Search endpoint where the user can search for other users or threads. The backend service captures the query and returns the matched users and threads.
- Status Codes:
200 OK – no error
400 Bad Request – problem in parsing the query string
500 Internal Server Error – problem in retrieving users or threads collection
- GET /user¶
Retrieve the logged-in user’s information.
- Status Codes:
200 OK – User found
400 Bad Request – Bad request (e.g., null username)
- GET /user/(username)¶
Retrieve user information by username.
- Parameters:
username (str) – The username to be searched.
- Status Codes:
200 OK – User found
400 Bad Request – Bad request (e.g., null username)
404 Not Found – User not found
- POST /user/block/(username)¶
Block a user by username.
- Parameters:
username (str) – The username to be blocked.
- Status Codes:
200 OK – User blocked successfully
400 Bad Request – Bad request (e.g., null username)
404 Not Found – User not found
- POST /user/unblock/(username)¶
Unblock a user by username.
- Parameters:
username (str) – The username of the user to be unblocked.
- Status Codes:
200 OK – User unblocked
400 Bad Request – Bad request (e.g., null username)
404 Not Found – User not found
- GET /user/(username)/is_blocked¶
Check if the logged-in user has blocked the given username.
- Parameters:
username (str) – The username to be checked.
- Status Codes:
200 OK – Block status found
400 Bad Request – Bad request (e.g., null username)
404 Not Found – User not found
- GET /user/(username)/is_me¶
Check if the logged-in user is the given username.
- Parameters:
username (str) – The username to be checked.
- Status Codes:
200 OK – User found
400 Bad Request – Bad request (e.g., null username)
404 Not Found – User not found