Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

Task API - Node.js and Python Implementations

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.

Features

  • 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.

Project Structure

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.


Setup and Installation

Choose which implementation you want to work with (Node.js or Python) and follow the corresponding setup instructions.

Node.js (Express) Setup

  1. Navigate to the Node.js directory:

    cd express_project
  2. Install Dependencies:

    Run the following command to install the necessary dependencies:

    npm install
  3. Run the Application:

    To run the Express application locally, use the following command:

    npm start

    The API will be available at http://localhost:3000.

  4. 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_project directory.


Python (FastAPI) Setup

  1. Navigate to the Python directory:

    cd fastapi_project
  2. Install Dependencies:

    Run the following command to install the necessary dependencies:

    pip install -r requirements.txt
  3. 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.

  4. Docker Setup for Python:

    If you want to run the Python version in a container, follow the Docker instructions provided in the fastapi_project directory.


Docker Setup

Both the Node.js and Python implementations are Dockerized, so you can easily run either version in a container.

Node.js (Express) Docker Setup

  1. Build the Docker image:

    docker build -t express-app .
  2. Run the Docker container:

    docker run -d -p 3000:3000 express-app

Python (FastAPI) Docker Setup

  1. Build the Docker image:

    docker build -t fastapi-app .
  2. Run the Docker container:

    docker run -d -p 8000:8000 fastapi-app

API Endpoints

Both implementations provide the same endpoints with identical functionality.

GET /tasks

Retrieve all tasks.

GET /tasks/{id}

Retrieve a task by its ID.

POST /tasks

Create a new task.

PUT /tasks/{id}

Update a task by its ID.

DELETE /tasks/{id}

Delete a task by its ID.


Testing with curl

You can use the following curl commands to test the API endpoints.

1. Get all tasks

curl -X GET http://localhost:3000/tasks  # For Node.js
curl -X GET http://localhost:8000/tasks  # For Python

2. Get a task by ID

curl -X GET http://localhost:3000/tasks/1  # For Node.js
curl -X GET http://localhost:8000/tasks/1  # For Python

3. Create a new task

curl -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 Python

4. Update a task by ID

curl -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 Python

5. Delete a task by ID

curl -X DELETE http://localhost:3000/tasks/1  # For Node.js
curl -X DELETE http://localhost:8000/tasks/1  # For Python

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages