Giter Club home page Giter Club logo

fastapibasiccrudproject's Introduction

Backend FastAPI

My Awesome FastAPI Project

This is a simple REST API built with Python and FastAPI and MongoDB for CRUD operations (Create, Read, Update, Delete) on Students. FastAPI is a powerful web framework for building APIs.

Install the project dependencies:

pip install -r requirements.txt

Run the application:

venv\Scripts\activate
uvicorn main:app --reload

The application will start and be available at http://localhost:8000.

API Endpoints

Retrieve a list of students:

GET /students

Returns a list of all students in the system:

curl http://localhost:8000/students/ -H "Accept: application/json"

Response:

[
    {
        "id": "7a2d72f9e92d4231ac6dd834aa7461d1",
        "name": "Jai",
        "age": 26,
        "address": 
        {
            "city": "Delhi",
            "country": "India"
        }
    },
    {
        "id": "4a1dddb9d74e427d9f8e6fdbe2e112a2",
        "name": "Adi",
        "age": 20,
        "address": 
        {
            "city": "Jaipur",
            "country": "India"
        }
    },
    {
        "id": "95f3bee04dad487eb54ae61a457201ea",
        "name": "Anuj",
        "age": 23,
        "address": 
        {
          "city": "Pune",
          "country": "India"
        }
    }
]

Retrieve details for a specific user:

GET /students/{user_id}

Returns details for a specific user with the given user_id:

curl http://localhost:8000/students/95f3bee04dad487eb54ae61a457201ea -H "Accept: application/json"

Response:

{
        "id": "95f3bee04dad487eb54ae61a457201ea",
        "name": "Anuj",
        "age": 23,
        "address": 
        {
          "city": "Pune",
          "country": "India"
        }
}

Add a new user

POST /students

API to create a student in the system. All fields are mandatory and required while creating the student in the system.

  • name (string, required): the name of the user
  • age (string, required): the email address of the user
  • address (string, required): the address for the user which includes city and country.
curl -X POST http://localhost:8000/students/
   -H 'Content-Type: application/json'
   -d '{
    "age": 31,
    "name": "Shyam",
    "address":
        {
            "country": "Japan",
            "city": "Tokyo"
        }
    }'

Response:

{
  "id": "34c8b3111bf34e1f8fbff33cb6b0a593"
}

Update an existing user

PATCH /students/{user_id}

Updates an existing user with the given user_id. The request body should include a JSON object with the following properties:

  • name (string): the new name for the user
  • age (int): the new age for the user
  • city (string): the new city for the user
  • country (string): the new country for the user
curl -X PUT http://localhost:8000/students/95f3bee04dad487eb54ae61a457201ea
     -H "Accept: application/json"
     -d '{"age": 24, "address":{"city": "Jaipur"}}'

Response:

{}

Delete a user

DELETE /students/{user_id}

Deletes the user with the given user_id:

curl -X DELETE http://localhost:8000/{student_id}

Response:

{}

Code credit

Code credits for this code go to Aman Khandelwal

fastapibasiccrudproject's People

Contributors

wolfblunt avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.