A Flask microservice to allow basic HTTP access to a simple in-memory database.
The database has all the basic CRUD functionality. It is intended for internal use so there is no system of authorization.
Routes:
- Read database entry
- Write database entry
- Update database entry
- Delete database entry
The API opens at the address http://localhost:4820/ by default.
GET
/db/<id>
Given an ID, returns the database entry.
EXAMPLE CALL:
requests.get("http://localhost:4820/db/1def569a-a49a-4d0e-9448-733ef0b60828")EXAMPLE OUTPUTS:
Object data
{
"id": "4ded3320-59bf-44df-b619-17e3bd9c9397",
"data": {
"word": "fish",
"number": 4
}
}String data
{
"id": "1def569a-a49a-4d0e-9448-733ef0b60828",
"data": "fish"
}Number data
{
"id": "e754e750-85f3-40cf-a345-8cf30750ccbd",
"data": 4
}POST
/db
Given data, stores the data in a database entry. The resulting new entry is returned.
EXAMPLE CALLS:
requests.post("http://localhost:4820/db", json={"word": "fish", "number": 4})
requests.post("http://localhost:4820/db", json="fish")
requests.post("http://localhost:4820/db", json=4)EXAMPLE OUTPUTS:
(same as from the 'Read database entry' endpoint)
{
"id": "79388c82-87e6-4528-accf-0bda421d71d9",
"data": {
"word": "fish",
"number": 4
}
}PUT
/db/<id>
Given data, changes the data of the given database entry matching the ID. The resulting updated entry is returned.
EXAMPLE CALLS:
requests.post("http://localhost:4820/db/79388c82-87e6-4528-accf-0bda421d71d9", json={"word": "bird", "number": 6})
...EXAMPLE OUTPUTS:
{
"id": "79388c82-87e6-4528-accf-0bda421d71d9",
"data": {
"word": "bird",
"number": 6
}
}DELETE
/db/<id>
Given an ID corresponding to an existing database entry, deletes the entry and returns 204.
EXAMPLE CALLS:
requests.delete("http://localhost:4820/db/79388c82-87e6-4528-accf-0bda421d71d9")
...EXAMPLE OUTPUTS:
No data with 204 return code
This program requires additional libraries to function. This installation shows the steps to install the requirements via pip inside a virtual environment.
Warning
The command to enter the Python Virtual environment differs by operating system. You can check the full list for your specific command. The POSIX version is listed in this example.
To run this program you must have Python 3 and pip installed. You can verify that the programs are installed with the following command:
python3 --version
pip --versionCreate a virtual environment:
python3 -m venv envEnter the virtual environment and install the dependencies:
source env/bin/activate
pip install -r requirements.txtThe requirements should now be installed into the virtual environment and the program can be run whenever you are within this virtual environment.
Enter the virtual environment if not already inside:
source env/bin/activateRun the program:
python3 src/main.py