- Python 3.7
- MongoDB
- PyCharm IDE (recommended)
git clone git@github.com:yariv1025/messaging-system-rest-api.git
pip install pipenv #Install pipenv and create the virtual environment
pipenv install #Install packages
pipenv install all --dev #Install all dev dependencies
pipenv lock #Generate a lockfile
- Use MongoDB Atlas website to create your own database and cluster
-
Add new configuration:
- Press + button
- Python
- name: APP
- Script path: "YOURS-PATH"\messaging-system-rest-api\src\app.py
- Environment variables: ;FLASK_ENV=development;FLASK_APP=./src/app.py;MONGO_USER="YOURS-USERNAME";MONGO_PASS="YOURS-PASSWORD";MONGO_URI="YOURS_DB_URI";SECRET_KEY="YOUR_SECRET_KEY"
- Python
- Press + button
-
Complete MongoDB URI should look like: f'mongodb+srv://{username}:{password}{mongo_uri}'
-
Open Postman
-
Create API collection
-
Create the next CRUD requests:
- POST:
- Create a new user | WEB_ROUTE/user
- Body fields: first_name, last_name, email, password
- Response:
- Status: 201
- Body:
* id: <> * first_name: <> * last_name: <> * email: <> * password: <> * created_at: <> * last_login: <>
- Status: 201
- Body fields: first_name, last_name, email, password
- Login | WEB_ROUTE/login
- Body fields: email, password
- Response:
- Status: 200
- Body: * status: <> * message: <> * access_token: <> * refresh_token: <>
- Status: 200
- Body fields: email, password
- Logout | WEB_ROUTE/oauth/logout
- Authorization Bearer Token filed: access_token
- Response:
- Status: 200
- Body: * message: <>
- Status: 200
- Authorization Bearer Token filed: access_token
- Refresh access token | WEB_ROUTE/oauth/refresh
- Authorization Bearer Token filed: access_token.
- Body:
- key: grant_type, value: refresh_token
- key: refresh_token, value: refresh_token
- key: grant_type, value: refresh_token
- Response:
- Status: 200
- Body: * user_id: <> * email: <> * exp: <> * new_access_token: <>
- Status: 200
- Authorization Bearer Token filed: access_token.
- Write message | WEB_ROUTE/messages
- Authorization Bearer Token filed: access_token.
- Body fields:
- key: sender, value: sender
- key: receiver, value: receiver
- key: subject, value: subject
- key: message, value: message
- key: sender, value: sender
- Response:
- Status: 201
- Body: * message_id: <>
- Status: 201
- Authorization Bearer Token filed: access_token.
- GET:
- Get all messages | WEB_ROUTE/messages
- Authorization Bearer Token filed: access_token.
- Response:
- Status: 200
- Body: * message_id: <> * sender_id: <> * sender_name: <> * receiver_name: <> * subject: <> * message: <> * created_at: <> * is_read: <>
- Status: 200
- Authorization Bearer Token filed: access_token.
- Get all messages | WEB_ROUTE/messages
- Get message by id | WEB_ROUTE/messages/<message_id>
- Authorization Bearer Token filed: access_token.
- Response:
- Status: 200
- Body: * message_id: <> * sender_id: <> * sender_name: <> * receiver_name: <> * subject: <> * message: <> * created_at: <> * is_read: <>
- Status: 200
- Authorization Bearer Token filed: access_token.
- DELETE:
- Delete message | WEB_ROUTE/messages/<message_id>
- Authorization Bearer Token filed: access_token.
- Response:
- Status: 200
- Body: number of deleted messages
- Status: 200
- Authorization Bearer Token filed: access_token.