Simple TODO API using PostgREST. Find more https://postgrest.org/.
# Use -d option to run containers in the background
docker-compose up -d
# View logs output form containers
docker-compose logs
Swagger config is available on http://localhost:3000. You can use online editor as user interface.
You can also generate Postman collection by importing swagger config directly on Postman.
Find more https://postgrest.org/en/v9.0/api.html#openapi-support.
# stop command will only stop the services, meanwhile down command will stop and destroy resources docker-compose stop
docker exec -it todo-database psql -U postgres
Some requests bellow need to be authenticated as authenticated_user
using a JWT token. You can generate one here, or use the following one.
export TOKEN=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoiYXV0aGVudGljYXRlZF91c2VyIn0.DpYcXq4Cd3g5vjWGwCETGZ3pYgnWcX3P-sAGkusHPpU
https://postgrest.org/en/v9.0/api.html#tables-and-views
curl http://localhost:3000/todos
https://postgrest.org/en/v9.0/api.html#operators
curl http://localhost:3000/todos?done=eq.true
https://postgrest.org/en/v9.0/api.html#ordering
curl http://localhost:3000/todos?order=due.desc,done.asc
https://postgrest.org/en/v9.0/api.html#limits-and-pagination
curl http://localhost:3000/todos?limit=5&offset=0
https://postgrest.org/en/v9.0/api.html#response-format
curl http://localhost:3000/todos \
-H "Accept: application/json"
curl http://localhost:3000/todos?id=eq.1 \
-H "Accept: application/vnd.pgrst.object+json"
https://postgrest.org/en/v9.0/api.html#insertions-updates
curl http://localhost:3000/todos -X POST \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{"task": "New task"}'
https://postgrest.org/en/v9.0/api.html#bulk-insert
curl http://localhost:3000/todos -X POST \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '[{"task": "New task 1"}, {"task": "New task 2"}]'
PUT replace a resource, meanwhile PATCH applies partial modifications.
https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PUT
https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PATCH
https://postgrest.org/en/v9.0/api.html#insertions-updates
https://postgrest.org/en/v9.0/api.html#put
curl http://localhost:3000/todos -X PATCH \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{"done": true}'
curl http://localhost:3000/todos -X PUT \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{"task": "New task", "done": true}'