This repository contains a Flask application that uses a PostgreSQL database in a Docker container. This app and database will run in isolated containers, making deployment and management easier.
In order to run this app you are going to need Docker and Docker Compose
- Docker: install Docker
- Docker Compose: install Docker Compose
Clone this repo anywhere you want and move into the directory:
git clone https://github.com/pkhorenyan/flask-api
cd flask-api
Start Docker Compose:
docker-compose up
This command creates and starts Flask and PostgreSQL containers.
Application will be available at http://127.0.0.1:5000
Shutting down:
docker-compose down
PostgreSQL container is configured to store data in a Docker volume. This means that all the data will remain intact between container restarts.
The purpose of this application is to connect to https://jservice.io/api/random and to retrieve quiz questions.
You can access https://127.0.0.1:5000/api/archive endpoint to see all questions that had been retrieved and saved to database. If no questions have been saved you'll see 'No data yet' message.
There are a couple of ways to retrieve questions:
- You can manually send POST request to endpoint https://127.0.0.1:5000/api/
curl -i -X POST -H 'Content-Type: application/json' -d '{"questions_num": integer}' https://127.0.0.1:5000/api/
- In Postman go to "Body" and then "raw". Choose JSON format and paste this:
{
"questions_num": integer
}where integer is a number of questions you would like to retrieve
First time you send POST request you'll get an empty JSON object but on the next request you'll get previous number of questions. All questions are being added to the database.