Coder Social home page Coder Social logo

basemax / simplefastpyapi Goto Github PK

View Code? Open in Web Editor NEW
13.0 2.0 10.0 48 KB

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

License: GNU General Public License v3.0

Python 100.00%
fastapi fastapi-crud fastapi-example fastapi-sample fastapi-user fastapi-users py python python-fastapi python3

simplefastpyapi's Introduction

Simple FastAPI Py

My Awesome FastAPI Project

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

Installation

Clone this repository to your local machine:

git clone https://github.com/BaseMax/SimpleFastPyAPI

Change into the project directory:

cd SimpleFastPyAPI

Install the project dependencies:

pip install -r requirements.txt

Run the application:

uvicorn main:app --reload

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

API Endpoints

Retrieve a list of users:

GET /users

Returns a list of all users in the system:

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

Response:

[
    {
        "email": "[email protected]",
        "id": 1,
        "password": "password1",
        "name": "Alice"
    },
    {
        "email": "[email protected]",
        "id": 2,
        "password": "password2",
        "name": "Bob"
    },
    {
        "email": "[email protected]",
        "id": 3,
        "password": "password3",
        "name": "Charlie"
    }
]

Retrieve details for a specific user:

GET /users/{user_id}

Returns details for a specific user with the given user_id:

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

Response:

{
    "email": "[email protected]",
    "id": 1,
    "password": "password1",
    "name": "Alice"
}

Add a new user

POST /users

Adds a new user to the system. The request body should include a JSON object with the following properties:

  • name (string, required): the name of the user
  • email (string, required): the email address of the user
  • password (string, required): the password for the user
curl -X POST http://localhost:8000/users/
   -H 'Content-Type: application/json'
   -d '{"name":"Ali","password":"123456", "email": "[email protected]"}'

Response:

{
    "email": "[email protected]",
    "password": "123456", 
    "id": 4, 
    "name": "Ali"
}

Update an existing user

PUT /users/{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
  • email (string): the new email address for the user
curl -X PUT http://localhost:8000/users/1
     -H "Accept: application/json"
     -d '{"name": "Reza", "email": "[email protected]"}'

Response:

{"message": "User updated successfully"}

Delete a user

DELETE /users/{user_id}

Deletes the user with the given user_id:

curl -X DELETE http://localhost:8000/2

Response:

{"message": "User deleted successfully"}

License

This project is licensed under the GPL-3.0 License - see the LICENSE file for details.

Copyright 2023, Max Base

simplefastpyapi's People

Contributors

aliiahmadi avatar dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

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