Code Monkey home page Code Monkey logo

fastapi-crud's Introduction

Repository for fastAPI CRUD Database operation

Prerequisites :

  • Create virtual environment for FastAPI
#create virtual environment
python -m venv ./venv

#activate virtual environment (Windows)
.\venv\Scripts\activate

#activate virtual environment (Linux/Mac)
source venv/bin/activate
  • Install libraries : fastapi, ASGI (Asynchronous Server Gateway Interface) server(in this case we will use Uvicorn), SQLAlchemy and psycopg2 to connect to postgres databases. You can type pip install requirements.txt for install all libraries.

  • Install postman for run API after run FastAPI apps. You can download here

Structure folder :

Lets define project structure bellow :

+-- app
| +-- __init__.py
| +-- crud.py
| +-- config.py
| +-- main.py
| +-- models.py
| +-- routes.py
| +-- schemas.py
+-- venv

How to Run

  • Type command bellow. It will run apps with default ip 127.0.0.1 and port 8000
cd app
uvicorn main:app --reload

image

  • Open Postman, type url http://127.0.0.1:8000 and methode GET then save as Home. Click Send button then will display output "Hallo"

image

  • Next define other request as bellow :
    • Request Name : Create New. URL : http://127.0.0.1:8000/book/create. Method : POST. Body: Choose raw and type

      {
        "parameter": {
          "title": "Apache Spark for Data Scientist",
          "description": "Book about Apache Spark for Data Scientist"
         }
      }
      

      save as Create New. Click Send button then will display Response 200 OK image

    • Request Name : Get All. URL : http://127.0.0.1:8000/book/. Method : GET. Save as Get All then click Send button will display output bellow

      image
    • Request Name : Get By Id. URL : http://127.0.0.1:8000/book/{id}(id with get from run request Get All). Method : GET. Save as Get By Id then click Send button will display output bellow

      image
    • Request Name : Update. URL : http://127.0.0.1:8000/book/update. Method : PATCH . Body: Choose raw and type

      {
      "parameter": {
          "id": "3",
          "title": "Apache Spark for Data Scientist",
          "description": "Book about Apache Spark for Data Scientist for Beginner"
          }
      }
      

      save as Update. Click Send button then will display output bellow

      image
    • Request Name : Delete. URL : http://127.0.0.1:8000/book/{id}(id with get from run request Get All). Method : DELETE. Save as Delete then click Send button will display output bellow

      image

fastapi-crud's People

Contributors

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