I've created my first api service with GET and POST methods and connection to my local PostgreSQL
Clone the repo
$ git clone https://github.com/sanzhik22/My_first_API_with_dbconnection/blob/main/README.md
Requires Python 3.11.3 # adjust it
Create a virtual environment and activeate it:
python -m venv /path/to/repo
# in venv directory:
Scripts/activate
Install dependencies in venv using pip
pip install -r requirements.txt
python main.py
Rename env.template file to .env file and edit it
MY_HOST = <<Host name>>
MY_DATABASE = <<Database name>>
MY_USER = <<Your user name to your postgres database>>
MY_PASSWORD = <<Your database user password>>
For running test we use test pytest library
pip install pytest
pythom -m pytest
/airport_data/<airport_code>
Method: GET
Querry Parammeters:
<airport_code>
- write airport code by which it will be selected
Returns
JSON:
{
"LED",
"Пулково",
"Санкт-Петербург",
"(30.262500762939453,59.80030059814453)",
}
if no such rows
{
'status': 'Couldnt find that location in datatbase'
}
if error
{
'status': type of error
}
/add-airport
Method: POST
Query Parameters:
Body:
JSON content with the following structure:
{
"city": "Кызылорда",
"airport_name": "Кызылординский государственный",
"coordinates": "(561,66557)"
}
Returns
json
{
'status': 'Row added to database'
}
if error
{
'status': type of error
}
All output logs saved in log.txt