# API Documentation
## User Endpoints
### User Login
- **Endpoint:** `/api/login`
- **Method:** `POST`
- **Description:** Authenticates a user and returns a JWT token.
#### Request
```json
{
"email": "user@example.com",
"password": "userpassword"
}
{
"token": "jwt_token_here",
"email": "user@example.com",
"username": "username_here"
}
-
400 Bad Request: Missing
email
orpassword
in request body. -
401 Unauthorized: Invalid email or password.
-
Endpoint:
/api/register
-
Method:
POST
-
Description: Registers a new user.
{
"username": "username_here",
"email": "user@example.com",
"password": "userpassword"
}
{
"username": "username_here",
"email": "user@example.com"
}
- 400 Bad Request: Invalid email format, password length less than 6, or missing required fields.
-
Endpoint:
/api/users
-
Method:
GET
-
Description: Retrieves all users.
[
{
"id": "user_id_here",
"fullName": "Full Name Here",
"username": "username_here",
"email": "user@example.com"
}
]
- 500 Internal Server Error: Error fetching users.
-
Endpoint:
/api/users/:id
-
Method:
GET
-
Description: Retrieves a user by ID.
{
"id": "user_id_here",
"fullName": "Full Name Here",
"username": "username_here",
"email": "user@example.com"
}
- 500 Internal Server Error: Error fetching user.
-
Endpoint:
/api/books
-
Method:
POST
-
Description: Creates a new book entry.
{
"name": "Book Title Here"
}
{
"id": "book_id_here",
"name": "Book Title Here",
"creator": "user_id_here"
}
-
401 Unauthorized: User not authenticated.
-
400 Bad Request: Missing
name
in request body.
-
Endpoint:
/api/books
-
Method:
GET
-
Description: Retrieves all books along with the creator's username.
[
{
"id": "book_id_here",
"name": "Book Title Here",
"creator": {
"username": "creator_username_here"
}
}
]
- 500 Internal Server Error: Error fetching books.
-
Endpoint:
/api/books/:id/favorite
-
Method:
POST
-
Description: Allows a user to favorite a book.
{
"bookId": "book_id_here"
}
{
"message": "Book favorited successfully"
}
-
401 Unauthorized: User not authenticated.
-
400 Bad Request: User trying to favorite their own book, already favorited the book, or has reached the maximum limit of 10 favorite books.
-
Endpoint:
/api/books/favorites
-
Method:
GET
-
Description: Retrieves a list of favorite books for the authenticated user.
[
{
"id": "book_id_here",
"name": "Book Title Here",
"creator": {
"username": "creator_username_here"
}
}
]
-
401 Unauthorized: User not authenticated.
-
500 Internal Server Error: Error fetching favorite books.