Mount a valid OpenAPI supporting REST API as a directory, and support CRUDL commands via file-system commands. Supports setting Bearer tokens for authentication into the API as well.
Directory structure is generated via parsing URL path specifications, and maps 1-to-1 to endpoints available on the API for consistency.
To handle nested URL structures under individual objects (i.e. /heroes/1/villains), all individual objects will be a directory and the data for the object will be contained in the data.json file.
- Python 3.11+ and Poetry
- System Dependencies: You must have FUSE and its development headers installed (e.g.,
libfuse-devandfuseon Ubuntu/Debian). - OpenAPI Documentation File: If needed, a simple FastAPI system is provided and can be used for investigation.
-
Install Dependencies
poetry install
If you want to use the Test API, include its dependencies using the following;
poetry install --with test_api
-
Test API (if required):
poetry run python -m test_api
You must provide a Swagger file URL when starting the server. This file will be read to determine the URL of the server and how to supply any authentication (if necessary).
poetry run python -m fs [OPTIONS] API_URL MOUNTPOINTAs an example, to mount the test api to a local mount directory;
mkdir test_api_fs
poetry run python -m fs http://localhost:8000/openapi.json test_api_fsIf you need to set Authorization headers, you can use the -H flag;
poetry run python -m fs http://localhost:8000/openapi.json -H Authorization "Basic aGVyb19tYW5hZ2VyOmFiYzEyMw==" test_api_fsNOTE You need to provide this header to access test_api_fs/heroes/*/villains/ or else it will be empty.
To remove the mounted directory, simply run
umount test_api_fsor whatever other directory you have mounted.
Using the Test API schema as our examples;
ls test_api_fs/heroesecho '{"age":52,"secret_name":"Brian","id":3,"name":"Test Hero 3"}' > test_api_fs/heroes/new.jsonAny edits to the new.json file will result in a POST request being sent.
cat test_api_fs/heroes/1/data.jsonsed s/oldvalue/newvalue/ test_api_fs/heroes/1/data.json > test_api_fs/heroes/1/data.jsonTemporary files cannot be created under the filesystem due to its nature so sed -i doesn't work as intended.
rm test_api_fs/heroes/2/data.json- For sake of ease, API objects are assumed to have either an
idorpkproperty, used as a parameter to the URLs. - If you have an API that does not reflect this and have ideas on how to expand this library to enable it, please send a PR!