My first api
The users base are a fake base.
- From the project directory, create the virtual environment :
python3 -m venv <venv>
- Activate the virtual environment :
- On Linux :
$ source <venv> / bin / activate
- On Windows Powershell :
PS C: \<venv>\Scripts\Activate
- On Linux :
- Install the necessary modules :
pip install –r requirements.txt
orpip3 install –r requirements.txt
- Start the server from the folder app :
uvicorn api: app
- Check the operating status of the API :
curl -X 'GET' 'http://localhost:8000/home' -H 'accept: application/json'
- Token request to authenticate :
curl -X 'POST' 'http://localhost:8000/token' \
-H 'accept: application/json' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-d 'grant_type=&username=<username>&password=<password>&scope=&client_id=&client_secret='
- Request the types of tests available :
curl -X 'GET' 'http://localhost:8000/uses' \
-H 'accept: application/json' \
-H 'Authorization: Bearer <token>'
- Ask the subjects according to the type of test chosen :
curl -X 'GET' 'http://localhost:8000/subjects?use=<type de test>' \
-H 'accept: application/json' \
-H 'Authorization: Bearer <token>'
- Ask for a questionnaire :
curl -X 'GET' 'http://localhost:8000/questions?nb_questions=<number>&subject=<subject>&use=<test type>' \
-H 'accept: application/json' \
-H 'Authorization: Bearer <token>'
- Token request to authenticate with role admin :
curl -X 'POST' 'http://localhost:8000/token' \
-H 'accept: application/json' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-d 'grant_type=&username=<username>&password=<password>&scope=admin&client_id=&client_secret='
- Add a question in the database :
curl -X 'POST' 'http://localhost:8000/admin' \
-H 'accept: application/json' \
-H 'Authorization: Bearer <token> ' \
-H 'Content-Type: application/json' \
-d '{
"question": "string",
"subject": "string",
"use": "string",
"correct": "string",
"responseA": "string",
"responseB": "string",
"responseC": "string",
"responseD": "string",
"remark": "string"
}'
Documentation in OpenAPI format can be accessed at :
http://localhost:8000/docs
Nicolas MARQUETTE