This repository provides two implementations of a simple Task API. One version is built with Node.js using the Express framework, and the other is built with Python using the FastAPI framework. The API allows you to perform basic CRUD (Create, Read, Update, Delete) operations on tasks.
Both implementations offer the same functionality and endpoint structure, so you can choose whichever language and framework you prefer for your project.
- GET
/tasks: Retrieve all tasks. - GET
/tasks/{id}: Retrieve a task by its ID. - POST
/tasks: Create a new task. - PUT
/tasks/{id}: Update an existing task by ID. - DELETE
/tasks/{id}: Delete a task by ID.
The project consists of two directories:
- express_project: The Node.js (Express) implementation of the Task API.
- fastapi_project: The Python (FastAPI) implementation of the Task API.
Both directories contain all the necessary code and instructions to build and run the API.
Choose which implementation you want to work with (Node.js or Python) and follow the corresponding setup instructions.
-
Navigate to the Node.js directory:
cd express_project -
Install Dependencies:
Run the following command to install the necessary dependencies:
npm install
-
Run the Application:
To run the Express application locally, use the following command:
npm start
The API will be available at
http://localhost:3000. -
Docker Setup for Node.js:
If you want to run the Node.js version in a container, follow the Docker instructions provided in the
express_projectdirectory.
-
Navigate to the Python directory:
cd fastapi_project -
Install Dependencies:
Run the following command to install the necessary dependencies:
pip install -r requirements.txt
-
Run the Application:
To run the FastAPI application locally, use the following command:
uvicorn main:app --reload
The API will be available at
http://localhost:8000. -
Docker Setup for Python:
If you want to run the Python version in a container, follow the Docker instructions provided in the
fastapi_projectdirectory.
Both the Node.js and Python implementations are Dockerized, so you can easily run either version in a container.
-
Build the Docker image:
docker build -t express-app . -
Run the Docker container:
docker run -d -p 3000:3000 express-app
-
Build the Docker image:
docker build -t fastapi-app . -
Run the Docker container:
docker run -d -p 8000:8000 fastapi-app
Both implementations provide the same endpoints with identical functionality.
Retrieve all tasks.
Retrieve a task by its ID.
Create a new task.
Update a task by its ID.
Delete a task by its ID.
You can use the following curl commands to test the API endpoints.
curl -X GET http://localhost:3000/tasks # For Node.js
curl -X GET http://localhost:8000/tasks # For Pythoncurl -X GET http://localhost:3000/tasks/1 # For Node.js
curl -X GET http://localhost:8000/tasks/1 # For Pythoncurl -X POST http://localhost:3000/tasks \
-H "Content-Type: application/json" \
-d '{"title": "New Task", "description": "New task description", "completed": false}' # For Node.js
curl -X POST http://localhost:8000/tasks \
-H "Content-Type: application/json" \
-d '{"title": "New Task", "description": "New task description", "completed": false}' # For Pythoncurl -X PUT http://localhost:3000/tasks/1 \
-H "Content-Type: application/json" \
-d '{"title": "Updated Task", "description": "Updated task description", "completed": true}' # For Node.js
curl -X PUT http://localhost:8000/tasks/1 \
-H "Content-Type: application/json" \
-d '{"title": "Updated Task", "description": "Updated task description", "completed": true}' # For Pythoncurl -X DELETE http://localhost:3000/tasks/1 # For Node.js
curl -X DELETE http://localhost:8000/tasks/1 # For Python