Job test project to:
- Set up postgresql database.
- Populate it with some tables and records.
- Launch python service, which lets us grab records from database.
Terminal promts is for Arch Linux. If you have another Linux distribution, feel free to google 'how to install pip', 'how to install with pip' and 'how to install postgresql' for your distribution!
sudo pacman -S postgresqlsudo su - postgres
initdb --locale en_US.UTF-8 -D /var/lib/postgres/data
exitsudo systemctl start postgresqlsudo systemctl status postgresql - check if service is actually running
sudo -u postgres psqlCREATE USER uno WITH ENCRYPTED PASSWORD '8.B(P8pDQeMH!';
CREATE DATABASE prueba;
GRANT ALL PRIVILEGES ON DATABASE prueba TO uno;
\c prueba postgres
GRANT ALL PRIVILEGES ON SCHEMA public TO uno;
\q
do not configure your db for remote access if you exposed your password somewhere!
- restart postgresql
sudo systemctl restart postgresql- connect to postgresql
psql -h localhost -d prueba -U uno -p 5432
\qsudo pacman -S python-pip
python -m pip install --break-system-packages psycopg
python -m pip install --break-system-packages flask
python -m pip install --break-system-packages jsonifygit clone "https://github.com/collinder/py-rest-service.git" ~/sencillo
cd ~/sencillo
python serv.py init- CTRL - C
cd ~/sencillo
python serv.py- Open your browser
- Go to http://127.0.0.1:5000/ - can you see all authors in json format?
- Go to http://127.0.0.1:5000/writers/1 - can you see all books of that author?
do not configure your db for remote access if you exposed your password somewhere!
that service may be vulnerable to sql injection - we are injecting string parameter from GET request into sql query directly