Endpoints
Authorization and User Management Endpoints
The following endpoints allow you to register a new user, and log in and out of the server.
/auth/register: Register a New User
Use this endpoint to create a new user account by providing a unique email address and a password. Upon successful registration, the user is created in the database and a success response is returned.
Endpoint Details
-
Method:
POST
-
URL:
/auth/register
Request Body
The request body should be a JSON object containing the user’s username (a valid email address) and password.
Field | Type | Description | Required | Example |
---|---|---|---|---|
username |
string | The user’s email address which serves as their unique username. | Yes | user@example.com |
password |
string | The user’s password. It will be hashed before being stored. | Yes | SecurePassword123! |
Example Request
|
|
Success Response
The server returns a 201 Created
status code upon successful registration. The response body contains the details of the newly created user account.
-
Status Code:
201 Created
-
Body:
application/json
Example Success Response
{
"id": "123e4567-e89b-12d3-a456-426614174000",
"username": "user@example.com",
"created_at": "2023-08-08T10:00:00Z"
}
Error Responses
This endpoint may return the following error codes:
Status Code | Description | Example Body |
---|---|---|
400 Bad Request |
The request body is malformed, or required fields (username , password ) are missing or invalid. |
Invalid request payload or Username and password are required |
409 Conflict |
A user account with the provided username (email) already exists. | Username 'user@example.com' already exists |
500 Internal Server Error |
An unexpected error occurred on the server (e.g., database connection issues, failure to hash password). | Failed to register user |
/auth/login: Log In
Use this endpoint to log in a user. Upon successful login, the user receives a JWT token, used for accessing protected endpoints.
Endpoint Details
-
Method:
POST
-
URL:
/auth/login
Request Body
The request body should be a JSON object containing the registered user’s username (a valid email address) and password.
Field | Type | Description | Required | Example |
---|---|---|---|---|
username |
string | The registered user’s username (email address). | Yes | user@example.com |
password |
string | The registered user’s password. | Yes | SecurePassword123! |
Example Request
|
|
Success Response
The server returns a 200 OK
status code upon successful login. The response body contains a JWT token. Use this token when accessing protected endpoints of the API while logged in.
-
Status Code:
200 OK
-
Body:
application/json
Example Success Response
|
|
Error Responses
Status Code | Description | Example Body |
---|---|---|
400 Bad Request |
The request body is malformed, or required fields (username , password ) are missing or invalid. |
Invalid request payload or `Username and password are required. |
401 Unauthorized |
The username or password is invalid. |
Invalid username or password |
`500 Internal Server Error | An unexpected error occured on the server (e.g. database connection issues, failure to generate a JWT token). | Failed to generate token |
/auth/logout: Log Out
Use this endpoint to log out a user. Upon successful logout, the server invalidates the user’s JWT token.
Endpoint Details
-
Method:
POST
-
URL:
/auth/logout
Request Body
There is no body content for this request.
Success Response
The server returns a 200 OK
status code upon successful logout. The response body is a simple plain-text string.
- Status Code:
200 OK
- Body:
text/plain
Example Success Response
|
|
Error Responses
Status Code | Description | Example Body |
---|---|---|
401 Unauthorized |
Authorization header is missing, invalid token format or claims, or token expiration time not found. | Invalid token format or claims |
500 Internal Server Error |
An unexpected error occured on the server (e.g. database connection issues, failure to revoke the JWT token). | Failed to revoke token |
Article Endpoints
/articles: Get User’s Articles
Use this end point to retrieve all articles from the server for the logged in user.
Endpoint Details
Method: GET
URL: /articles
Request Body
There is no content for the request body.
Success Response
The server returns a 200 OK
status code upon successful retrieval of the personal reading list of articles. The response body contains a list of articles and their details, such as URL, title, summary, and status.
Status Code: 200 OK
Body: application/json
Example Success Response
|
|
Error Responses
This endpoint may return the following error codes:
Status Code | Description | Example Body |
---|---|---|
401 Unauthorized |
User ID was not found. | Invalid username or password |
500 Internal Server Error |
An unexpected error occurred on the server (e.g., database connection issues, failure to retrieve articles). | Failed to fetch articles |
/articles: Post User’s Article
Use this end point to save an article to the logged-in user’s personal reading list.
Endpoint Details
-
Method:
POST
-
URL:
/articles
Request Body
The request body contains the URL for the article to be saved to the user’s reading list.
Field | Type | Description | Required | Example |
---|---|---|---|---|
URL |
string | The URL for the article to be saved. | Yes | http://example.com/article-19 |
Example Request
|
|
Success Response
The server returns a 201 Created
status code upon successfuly saving the article’s URL. The response body contains the saved article’s identifier and the logged in user identifier. Initially, the status
is set to processing
while the server is in the process of retrieving the article’s title and creating a summary and tags for the article. This process may take a minute or two.
Status Code: 201 Created
Body: application/json
Example Success Response
|
|
Error Responses
This endpoint may return the following error codes:
Status Code | Description | Example Body |
---|---|---|
400 Bad Request |
Invalid request payload or missing fields. | Invalid request payload or URL is required |
401 Unauthorized |
User ID not found. | User ID not found |
500 Internal Server Error |
An unexpected error occurred on the server (e.g., database connection issues, failure to submit article). | Failed to sumbit article |
/articles/{id}: Get Article By ID
Use this endpoint to retrieve an article by including the ID in the endpoint.
Endpoint details
-
Method:
GET
-
URL:
/articles/{id}
Request Body
There is no content for the request body.
Success Response
The server returns a 200 OK
status code upon successfully retrieving the article specified by the ID in the endpoint. The response body contains the article details.
Example Success Response
|
|
Error Responses
This endpoint may return the following error codes:
Status Code | Description | Example Body |
---|---|---|
400 Bad Request |
Article ID must be included in the endpoint. | Article ID is required |
401 Unauthorized |
User ID not found. | User ID not found |
404 Not Found |
Article was not found for this user. | Article not found or not owned by user |
500 Internal server error |
An unexpected error occurred on the server (e.g., database connection issues, failure to retrieve article). | Failed to fetch article |
/articles/{id}: Delete Article by ID
Use this endpoint to delete an article by including the ID in the endpoint.
Endpoint Details
-
Method:
DELETE
-
URL:
/articles/{id}
Request Body
There is no content for the request body.
Success Response
The server returns a 204 No Content
upon successful deletion of the article from the user’s personal reading list.
Example Success Response
There is no content in the response body.
Error Responses
This endpoint may return the following error codes:
Status Code | Description | Example Body |
---|---|---|
400 Bad Request |
Article ID must be included in the endpoint. | Article ID is required |
401 Unauthorized |
User ID not found. | User ID not found |
404 Not Found |
Article was not found for this user. | Article not found or not owned by user |
500 Internal server error |
An unexpected error occurred on the server (e.g., database connection issues, failure to delete article). | Failed to delete article |
/articles/{id}/status: Update Article’s Status
Use this endpoint to update an article’s status by including the article ID in the endpoint, and the new status in the request body.
Endpoint Details
-
Method:
PUT
-
URL:
/articles/{id}/status
Request Body
The request body contains the new status for the specified article in the logged-in user’s personal reading list.
Field | Type | Description | Required | Example |
---|---|---|---|---|
status |
string | The new status of the article. | Yes | read |
Example Request
|
|
Success Response
The server returns a 200 OK
status code upon successful update of the article’s status.
Example Success Response
|
|
Error Responses
This endpoint may return the following error codes:
Status Code | Description | Example Body |
---|---|---|
400 Bad Request |
Article ID must be included in the endpoint. | Article ID is required |
401 Unauthorized |
User ID not found. | User ID not found |
404 Not Found |
Article was not found for this user. | Article not found or not owned by user |
500 Internal server error |
An unexpected error occurred on the server (e.g., database connection issues, failure to update article status). | Failed to update article status |
/articles/{id}/tags: Update Article’s Tags
Use this endpoint to update the tags for an article by including the article ID in the endpoint, and the updated list of tags in the request body.
Endpoint Details
-
Method:
PUT
-
URL:
/articles/{id}/tags
Request Body
The request body should be a JSON object containing the updated list of tags for the article.
Field | Type | Description | Required | Example |
---|---|---|---|---|
tags |
array of strings |
The updated list of tags for the article | Yes | ["AOL"," Dial-up Internet"] |
Example Request
|
|
Success Response
The server returns a 200 OK
status code upon successful update of the article’s tags. The response body contains a json object with a success message.
Example Success Response
|
|
This endpoint may return the following error codes:
Status Code | Description | Example Body |
---|---|---|
400 Bad Request |
Article ID must be included in the endpoint and tags cannot be empty. | Article ID is required or Tags cannot be empty |
401 Unauthorized |
User ID not found. | User ID not found |
404 Not Found |
Article was not found for this user or not owned by user. | Article not found or not owned by user |
500 Internal server error |
An unexpected error occurred on the server (e.g., database connection issues, failure to update article tags). | Failed to update article tags |
Tags Endpoint
/tags: Get All Tags for a User
Use this endpoint to retrieve all unique tags from all articles for the logged-in user.
Endpoint Details
-
Method:
GET
-
URL:
/tags
Request Body
There is no content for the request body.
Success Response
The server sends a 200 OK
status code upon successfully retrieving all unique tags for the logged-in user.
Example Success Response
|
|
Error Responses
This endpoint may return the following error codes:
Status Code | Description | Example Body |
---|---|---|
401 Unauthorized |
User ID not found. | User ID not found |
500 Internal server error |
An unexpected error occurred on the server (e.g., database connection issues, failure to update article tags). | Failed to fetch tags for user |