Application case
The REST web interface we are describing here is designed to support a bibliography management system.Users can register bibliographic references, access them, search through them, remove them or modify them using a JSON patch. Let's first see how a bibliographic reference looks like in JSON which can be retrieved from http://app.jaqpot.org:8880/jaqpot/services/bibtex/SopNtoSar15.
Notice that, for the sake of this example, we have deliberately omitted the conference location which is usually reported; using JSON patch we will add the additional field address to report this location.
JSON Patch in a nutshell
A JSON patch document consists of a series of modification directives which are triples which consist of (i) a modification method, (ii) the path to be modified and (iii) the value used to update the old value. JSON Patch comprises the following modification methods: add, remove, replace, move, copy and test.A concise tutorial for JSON Patch can be found at jsonpatch.com along with other useful links. I encourage the reader to take some time to go through it.
JSON Patch in REST
In order to use the JSON patch specification in a REST framework one needs the following components:- A RESTful web service with JSON support
- The HTTP method PATCH - see RFC 5789.
- A JSON Patch engine which combines JSON documents with JSON patches to produce patched JSONs.
The web service, upon successful completion of the operation returns a status code 200 and the updated JSON in the response body.
The BibTeX case
Here is the BibTeX REST API:The BibTeX REST API. Click on the image to magnify it. |
Clients can list all BibTeX entries on the server (paginated), create new bibtex entries, get the representation of a bibtex entry in JSON, apply PUT or DELETE and finally, apply a PATCH as discussed before.
The PATCH API is as follows:
The PATCH API. Click on the image to magnify it. |
Clients need to specify the id of the BibTeX entry they want to modify and provide, in the request body, the JSON PATCH document. Notice that the content-type is application/json-patch+json.
Let us use this interface to add an address field to the above BibTeX entry. The PATCH we have to use is as follows:
[
{
"op": "add",
"path": "/address",
"value": "Torremolinos, Spain"
}
]
Here is the response:
As one can see, the field address has been added.
So, that's all folks... you can experiment with this interface.
This is part of the open-source project JAQPOT Quattro; you can find the source code on github.
this tool will help your reader to format json data http://jsonformatter.org
ReplyDeleteAwesome, thanks!
Delete