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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"meta" : { | |
"comments" : [ "latest conf publication" ], | |
"descriptions" : [ "Presented in MED2015" ] | |
}, | |
"author" : "P. Sopasakis and S. Ntouskas and H. Sarimveis", | |
"title" : "Robust model predictive control for discrete-time fractional-order systems", | |
"bookTitle" : "Mediteranean Conference on Control and Automation (MED 2015, IEEE)", | |
"year" : "2015", | |
"key" : "SopNtoSar15", | |
"bibType" : "Inproceedings", | |
"createdBy" : "guest", | |
"_id" : "SopNtoSar15" | |
} |
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:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"meta": { | |
"comments": [ | |
"latest conf publication" | |
], | |
"descriptions": [ | |
"Presented in MED2015" | |
] | |
}, | |
"author": "P. Sopasakis and S. Ntouskas and H. Sarimveis", | |
"title": "Robust model predictive control for discrete-time fractional-order systems", | |
"bookTitle": "Mediteranean Conference on Control and Automation (MED 2015, IEEE)", | |
"address": "Torremolinos, Spain", | |
"year": "2015", | |
"key": "SopNtoSar15", | |
"bibType": "Inproceedings", | |
"createdBy": "guest", | |
"_id": "SopNtoSar15" | |
} |
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