Messaging API that allows to manage messages between users.
- Signup - Create a new user account by providing username and password.
- Login - Authenticate existing users with username and password.
- Write Message - Authenticated users can send messages to others with subject and body.
- Get User Messages - Get all messages sent to or from an authenticated user.
- Get Unread User Messages - Get all unread messages for an authenticated user.
- Read Message - Get a specific message by ID and mark as read if accessed by receiver.
- Delete Message - Allow sender or receiver to delete a specific message.
- Token Authentication - Only authenticated users can access endpoints. Users get a token on signup/login that must be included in the Authorization header.
To run the project, follow these steps:
Rename the .example.env file to .env
mv .example.env .envOpen the .env file and fill in the necessary information where indicated.
Build and run the Docker containers using docker-compose.
docker-compose up --buildAccessing the Backend:
Once the containers are up and running, the server will be accessible at:
http://0.0.0.0:8000/Using the Django Admin:
To access the Django Admin interface, use the following URL:
http://0.0.0.0:8000/admin/Username: admin
Password: admin
Create a new user account.
POST /api/users/signup/
Request body:
{
"username": "new_user",
"password": "secret"
}Returns auth token on success.
After signing up a new user, copy the returned auth token , your username , and password , then update the following variables in the Postman collection:
token - Set this to the auth token received after signup
current_user - Set this to your username
password - Set this to your password
This will allow you to make authenticated requests to the API after registering a new user account.
Authenticate an existing user.
POST /api/users/login/
Request body:
{
"username": "your_username",
"password": "your_password"
}Returns auth token on success.
Get a list of messages for the authenticated user.
GET /api/messages/
Create a new message.
POST /api/messages/create/
Request body:
{
"from_user": "jane_doe",
"to_user": "your_username",
"subject": "Meeting invite",
"body": "Let's meet at 2pm tomorrow."
}Get a list of unread messages for the authenticated user.
GET /api/messages/unread/
Get a specific message.
GET /api/messages/{message_id}/
Update an existing message.
PUT /api/messages/{message_id}/
Request body same as compose message.
Delete a message.
DELETE /api/messages/{message_id}/