This is a simple Flask API that provides endpoints to create, read, update, and delete JSON bins in a SQLite database. Each bin is identified by a unique ID, and contains a JSON object.
To install and run the JSON Bin API, follow these steps:
- Clone this repository:
git clone https://github.com/example/json-bin-api.git
- Install the required dependencies:
pip install -r requirements.txt
- Start the API server:
python app.py
The API server should now be running at http://localhost:5000.
To create a new JSON bin, send a POST request to the /bins endpoint with a JSON payload that contains a name field and a json field:
$ curl -X POST -H "Content-Type: application/json" -d '{"name": "mybin", "json": {"foo": "bar"}}' http://localhost:5000/bins
{"id": "ZUO_MupYIZgn"}
This will create a new bin with a unique ID and the given name and JSON object.
To retrieve the JSON object from a bin by its ID, send a GET request to the /bins/<bin_id>
endpoint:
$ curl http://localhost:5000/bins/ZUO_MupYIZgn
{"foo": "bar"}
This will return the JSON object as a string.
To update the JSON object in a bin by its ID, send a PUT request to the /bins/<bin_id>
endpoint with a JSON payload that contains a json field:
$ curl -X PUT -H "Content-Type: application/json" -d '{"json": {"foo": "baz"}}' http://localhost:5000/bins/ZUO_MupYIZgn
This will update the JSON object in the bin with the new object.
To delete a bin by its ID, send a DELETE request to the /bins/<bin_id>
endpoint:
$ curl -X DELETE http://localhost:5000/bins/ZUO_MupYIZgn
This will delete the bin with the given ID.