This repository contains a Flask application that provides RESTful APIs to manage stores, items, tags, and user authentication. The project is structured to facilitate easy development and extension of its core functionalities.
- User Registration and Authentication: Secure user creation and authentication using JWT tokens.
- Store Management: CRUD operations for managing stores.
- Item Management: CRUD operations for managing items within stores.
- Tag Management: CRUD operations for tagging items for better organization and searchability.
- Email Notifications: Background task processing for sending email notifications using Redis Queue (RQ).
- Python 3.10 or higher
- Redis server (for RQ background tasks)
-
Clone the repository:
git clone https://github.com/amnotme/rest-apis-flask.git
-
Navigate into the project directory:
cd rest-apis-flask
-
Install dependencies using Pipenv (or pip, and create a virtual environment if necessary):
pipenv install
or
pip install -r requirements.txt
-
Set up environment variables by copying the
.env.example
to.env
and modifying it with your settings:cp .env.example .env
-
(If applicable) Run database migrations:
flask db upgrade
- Activate the virtual environment (if using Pipenv):
pipenv shell
- Start the Flask Application
flask run
The following sections describe the available CRUD operations for each resource. Replace :id
with the actual ID of the resource.
User Management
- Register a new user:
POST /register
- Body:
{ "username": "user1", "password": "pass", "email": "[email protected]" }
- Body:
- User login:
POST /login
- Body:
{ "username": "user1", "password": "pass" }
- Body:
- User logout:
POST /logout
- Requires valid JWT token.
Store Management
- Create a store:
POST /store
- Body:
{ "name": "My Store" }
- Requires authentication.
- Body:
- Get a store:
GET /store/:id
- Update a store:
PUT /store/:id
- Body:
{ "name": "New Store Name" }
- Requires authentication.
- Body:
- Delete a store:
DELETE /store/:id
- Requires authentication.
- List all stores:
GET /stores
Item Management
- Create an item:
POST /item
- Body:
{ "name": "My Item", "price": 19.99, "store_id": 1 }
- Requires authentication.
- Body:
- Get an item:
GET /item/:id
- Update an item:
PUT /item/:id
- Body:
{ "name": "New Item Name", "price": 29.99 }
- Requires authentication.
- Body:
- Delete an item:
DELETE /item/:id
- Requires authentication.
- List all items:
GET /items
Tag Management
- Add a tag to an item:
POST /tag
- Body:
{ "name": "electronics", "item_ids": [1, 2, 3] }
- Requires authentication.
- Body:
- Get all tags for an item:
GET /tags/item/:item_id
- Update a tag:
PUT /tag/:id
- Body:
{ "name": "updated tag" }
- Requires authentication.
- Body:
- Delete a tag:
DELETE /tag/:id
- Requires authentication.