Giter Site home page Giter Site logo

python-flask-exercise's Introduction

basic-db

simple CRUD API to connect to MySQL db

  • clone the repository or just the folder basic-db

  • cd to directory

  • pip install -r requirements.txt

  • Database Setup Flask has support for several relational database management systems, including SQLite, MySQL, and PostgreSQL. MySQL is used for this exercise. Along with Flask-SQLAlchemy (Python-SQL Object Relational Mapper) and mysqlclient (Python 3 interface to MySQL. It will help us connect the MySQL database to the app.)

    mysql -u root

    Once in mysql CLI:

    `CREATE USER '{username}'@'localhost or {server IP}' IDENTIFIED BY '{password}';
    
    `CREATE DATABASE somedatabasename;`
    
    `GRANT ALL PRIVILEGES ON somedatabasename . * TO '{username}'@'localhost or {server IP}';`
    
    `ALTER USER '{username}'@'localhost or {server IP}' IDENTIFIED WITH mysql_native_password BY 'youpassword';
    
  • make FLASK_APP variable

    For WindowsOS: set FLASK_APP=basicapi.py

    For MacOS: export FLASK_APP=basicapi.py

  • Migrations allow us to manage changes we make to the models, and propagate these changes in the database. Python package flask-migrate

    flask db init creates a migrations directory in the project directory

    flask db migrate creates migration

    flask db upgrade apply migration

  • Set up is all completed run flask run in terminal at the directory

  • List of APIs:

    [GET] /delivery                                retrun JSON of all delivery enteries 
    
    [POST] /delivery                               create a delivery entery (fields: businesstype, clientname, order_ID, comment)
    
    [GET] /delivery/<order_id>                     retrun JSON of delivery entry matching `order_id`
    
    [PUT] /delivery/<order_id>                     update delivery entry matching `order_id`
    
    [DELETE] /delivery/<order_id>                  delete delivery entry matching `order_id`
    
    [GET] /shippment                               retrun JSON of all delivery enteries 
    
    [POST] /shippment                              create a delivery entery (fields: ship_ID, contact_info, ship_area, ship_district, driver, car_type, car_ID, is_elevator, floors_byhand, amount_collect, comment)
    
    [GET] /shippment/<ship_id>                     retrun JSON of delivery entry matching `ship_id`
    
    [PUT] /shippment/<ship_id>                     update delivery entry matching `ship_id`
    
    [DELETE] /shippment/<ship_id>                  delete delivery entry matching `ship_id`
    

References:

python-flask-exercise's People

Contributors

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