Example for using a web REST API to access a mongodb database
One-time setup of a virtualenv using ./setupenv.sh
.
Then, load the env using . env/bin/activate
.
python server.py
, which should start a local server listening on port 8080.
You'll also need a mongodb for local testing. Recommendation is:
docker run --rm -it --network=host mongo:3
A REST API can be used simply:
curl -XPOST -H "Authorization: bearer $(python create_token.py)" \
-d '{"id": 1, "result": 12345}' http://localhost:8080/api/test
A Dockerfile
is already provided.