This project is a simple social media platform where users can create, read, update, and delete posts. Users can also register, log in, and log out.
To run this project, you need to have Python 3.x and pip installed on your machine.
- Clone the repository: git clone https://github.com/Goltzishpt/content_api
- Navigate to the project directory:
cd content_api
- Install the required dependencies:
pip install -r requirements.txt
- Set the environment variables by creating a .env file in the project's root directory: makefile
SECRET_KEY=<your-secret-key>
REDIS_HOST=<redis-host>
REDIS_PORT=<redis-port>
REDIS_DB=<redis-db>
To run the application, execute the following command in the project's root directory:
python main.py
This will start the Flask development server. You can access the application at http://localhost:5000/.
This file initializes the Flask application.
This file contains the configuration variables for the Flask application.
This file contains the functions for user authentication.
This file contains the functions for post creation, retrieval, update, and deletion.
This file creates and returns the Flask application instance.
This file contains the functions for managing user sessions using Redis and JSON Web Tokens (JWT).
This file maps the URLs to the corresponding views (functions) for handling requests.
- Registration To register a new user, send a POST request to /registration with the following JSON data:
{
"username": "your-username",
"password": "your-password"
}
- Login To log in, send a POST request to /login with the following JSON data:
{
"username": "your-username",
"password": "your-password"
}
If the credentials are valid, the response will contain a JSON Web Token (JWT) that should be used to authenticate the user in subsequent requests.
- Logout To log out, send a POST request to /logout with the JWT in the Authorization header:
Authorization: Bearer <jwt>
- Create a Post To create a new post, send a POST request to /post with the following JSON data:
{
"title": "post-title",
"body": "post-body"
}
Include the JWT in the Authorization header to authenticate the user.
-
Show All Posts To retrieve all posts, send a GET request to /post.
-
Show a Post To retrieve a specific post, send a GET request to /post/ where is the ID of the post.
-
Update a Post To update a post, send a PUT request to /post/ with the following JSON data:
{
"title": "updated-post-title",
"body": "updated-post-body"
}
Include the JWT in the Authorization header to authenticate the user.
- Delete a Post To delete a post, send a DELETE request to /post/ where is the ID of the post.
Include the JWT in the Authorization header to authenticate the user.
This project was created by Goltzishpt.