This is a simple application emulating a basic REST API. It allows CRUD operations (Create, Read, Update, Delete) on different collections, where each collection is represented as a JSON file in the file system. If the collection does not exist, it is automatically created.
This becomes particularly handy during front-end development, especially when the back-end is still in the process of being develop.
By default, the app will listen on localhost:5800. If you need to change the HOST and PORT, you can pass the values as arguments. See below for the use of arguments.
Enter http://localhost:5800 to see the available collections.
curl -X GET http://localhost:5800/api/<collection>
Note: by default you will get 30 results, you can pass "skip" & "limit" query string to get more results. For example:
curl -X GET http://localhost:5800/api/<collection>?skip=10&limit=5
Will discard the initial 10 elements and only transmit the remaining 5.
curl -X GET http://localhost:5800/api/<collection>/<id>
curl -X POST -H "Content-Type: application/json" -d '{"field1":"value1", "field2":"value2"}' http://localhost:5800/api/<collection>
curl -X PUT -H "Content-Type: application/json" -d '{"field1":"new_value1", "field2":"new_value2"}' http://localhost:5800/api/<collection>/<id>
curl -X DELETE http://localhost:5800/api/<collection>/<id>
curl -X POST -H "Content-Type: application/json" -d '{"name":"New Item", "value":42}' http://localhost:5800/api/example
curl -X GET http://localhost:5800/api/example
curl -X GET http://localhost:5800/api/example/1
curl -X PUT -H "Content-Type: application/json" -d '{"name":"Updated Item", "value":99}' http://localhost:5800/api/example/1
curl -X DELETE http://localhost:5800/api/example/1
Usage: static-api [OPTIONS]
Options:
-i, --host <HOST> IP address of the server [default: localhost]
-p, --port <PORT> Port that will listen to the server [default: 5800]
-h, --help Print help
Example:
./static-api --port 5555 --host 0.0.0.0