A minimal Python REST microservice datastore, which can be in-memory or JSON file backed.
Runs in-memory only by default, or file-backed if a file name is supplied as a command line argument.
Once running, go to the root URL to explore the API using Swagger UI.
Requires at least Python 3, tested with 3.5.
Relies on Flask and Flask-RESTPlus for the webserver and REST API, and TinyDB for the JSON database.
To get these clone the repository, open a terminal inside the repository directory and run:
$ pip install -r requirements.txt
Run with -h
for full usage options.
$ python microstore.py -h
Run the tests with python test_microstore.py
.
NOTE: All API methods are behind a /api
base URL (Swagger UI hides this away at the very bottom of the web page).
You can explore the API using Swagger UI by opening the root URL (that is printed to the terminal when you run the server) in your web browser - see an example image of this in action below.
You can integrate with a client that supports swagger/OpenAPI schemas by just reading the schema directly from /api/schema
.
In short though, you can PUT
JSON data to /api/apps/<your-app-name-here>
as the data
key of an object:
{
"data": {
"any_data": "you_like_here"
}
}
and later retrieve it with a GET
on the same URL, DELETE
it, or replace it with another PUT
.
A dockerfile is included to create a containerised microservice - build and run from the repository directory with:
sudo docker build -t microstore:latest .
sudo docker run -p 5000:5000 microstore
Now you can navigate to http://127.0.0.1:5000/
in your web browser to access the SwaggerUI of the container.
-
Not production ready. This is designed for simple prototyping use, not for performance at huge load, and does not meet production security requirements.
-
Single threaded. Flask will run single-threaded by default, creating a single synchronous server on a single thread capable of serving only one client at a time, and TinyDB does not support threaded access.