First we need to configure Python development environments and install dependencies :
$ pip install -r requirements.txt
How to run
$ python3 routes.py
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
Now let's create a complete CRUD (create, read, update and delete) for the database connection.The application has endpoints for creating, updating, deleting and querying orders.
This method get_pedidos()
returns all requests from the database:
@app.route('/')
def get_pedidos():
The method add_pedido()
adds orders:
@app.route('/add', methods=["POST"])
def add_pedido():
pedido = request.get_json()
{
"cliente": "felipe",
"produto": "camarão internacional",
"valor": "139.98"
}
The method edit_pedidos(id)
edit orders:
@app.route('/edit/<id>', methods=['PUT'])
def edit_pedidos(id):
pedido_alterado = request.get_json()
{
"cliente": "felipe",
"produto": "camarão internacional",
"valor": "139.98"
}
The method delete_pedidos(id)
delete orders:
@app.route('/delete/<int:id>', methods=['DELETE'])
def delete_pedidos(id):