jarutis / hellopostgre

Sample REST api with Flask

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Toy example of RESTful api

Flask based API with PostgreSQL. Uses distroless docker image for app.

Using distroless python results in 72 MB image size versus 199 MB using 3.7-slim-buster.

demo

Usage

Start app with PostgreSQL server:

docker-compose up

Get all phonebook entries:

curl -X GET localhost:5000/book/entries

Get entry by id:

curl -X GET localhost:5000/book/1

Add new entry:

curl -X POST \
  -d '{"name":"boo", "phone":"+123"}' \
  -H 'Content-Type: application/json' \
  http://0.0.0.0:5000/book

Update existing entry:

curl -X PUT \
  -d '{"name":"bob", "phone":"+432"}' \
  -H 'Content-Type: application/json' \
  http://0.0.0.0:5000/book/1

Delete entry:

curl -X DELETE http://0.0.0.0:5000/book/1

References

[1] https://hackersandslackers.com/flask-routes/
[2] https://www.vinaysahni.com/best-practices-for-a-pragmatic-restful-api

About

Sample REST api with Flask


Languages

Language:Python 83.5%Language:Dockerfile 13.2%Language:TSQL 3.3%