Basic CRUD API written in Python3 with Flask and SQLite.
- First you need to create your virtual enviorment and then clone this repo.
- Install the requirements: pip install -r requirements.txt
- cd to src folder and run flask shell to create the database
- from app import db
- db.create_all()
- exit()
- Now to run the app do the following:
- export FLASK_APP=app.py
- flask run
- Examples of requests and responses can be seen in Postman JSON file.
GET /v1
- Response:
{
"Message": "Basic CRUD API.",
"Result": true
}
GET /v1/user/list
- Response:
[
{
"cpf": "12332112334",
"created_on": "Sun, 14 Aug 2022 13:24:35 GMT",
"password": "3",
"role": true,
"updated_on": "Mon, 15 Aug 2022 02:01:05 GMT"
}
]
GET /v1/user/<id>
- Request: /v1/user/1
- Response:
{
"cpf": "20",
"create_on": "Mon, 15 Aug 2022 16:52:54 GMT",
"password": "1",
"role": false,
"updated_on": "Mon, 15 Aug 2022 16:52:54 GMT"
}
POST /v1/user
- Request: /v1/user
- Body:
{ "cpf":"200", "password": "1", "role": true }
- Response: "User 200 create on 2022-08-15 16:52:54.195903"
PUT /v1/user/<id>
- Request: /v1/user/1
- Param: token
- Body:
{ "cpf":"20", "password": "19110", "role": true }
- Response:
{
"Message": "User 1 successfully updated.",
"Result": true
}
DELETE /v1/user/<id>
- Request: /v1/user/2
- Param: token
- Response:
{
"Message": "User 2 successfully deleted.",
"Result": true
}
POST /v1/login
- Request: /v1/login
- params: token
- Response:
{
"Message": "User 1 is logged in.",
"Result": true,
"expiration_date": "Mon, 15 Aug 2022 18:07:31 GMT",
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJjcGYiOiIyMCIsImV4cCI6MTY2MDU4Njg1MX0.M_dQqap0hT4LzX0AFWcZRTNVsG6MOD2KGmk4IP5AGRY"
}