TODO: copy from Web Services API (Design Page) once it is finalized
When saving or editing a property on a "Concept" object, the conceptDatatype property can be simply the uuid. In addition, for most metadata, the "name" is unique across all active metadata, so that can also be used in place of the uuid when saving as well (POST or PUT).
The objects returned by web service calls are variable in their properties. In general there are three different representations that exist: ref, default, full. It is possible for modules to provide more representations for their objects. (TODO: document what method to call to get the available reps)
To change between representations, use the "v" query parameter:
...?v=default is invalid. Simply leave that parameter off.
Web service calls that return lists of objects will put those objects into the "ref" representation.
When an object is a child resource on another object (e.g. conceptDatatype property on Concept object) the full ConceptDatatype object is not returned by default. Instead a "ref" kind of class with String properties for
links, and a
display fills the concept.conceptDatatype property. The ref looks like this:
To fetch the full ConceptDatatype data, a second call to the links.self uri:
http:/../openmrs/ws/rest/conceptdatatype/8d4a4488-c2cc-11de-8d13-0010c6dffd0f is needed.
This representation is returned for objects when there is no "v=" parameter given. Most properties will be included and "refs" of some subobjects will also be listed.
The full representation is meant when to be used when subsequent calls are not desired or you need some uncommonly needed properties (like audit info).
Nearly every method in the OpenMRS API requires authentication, therefore, some every method in the webservices module needs to have an authenticated user in order to work.
There is a filter defined on the module that intercepts all calls and authenticates the given request.
Currently only BASIC authentication is supported. Header arguments values of __ and __ are expected.
Alternatively, a session token can be used. GET /openmrs/ws/rest/session with the BASIC credentials will return the current token value. This token should be passed with all subsequent calls as a cookie named jsessionid=token.
(available with OpenMRS v1.9.0 revision 20638 and higher)
The module also adds an ETag to response headers when presenting resources to clients. ETags have been implemented in shallow-mode (i.e. they save client bandwidth, but not server-side processing). As described here, as a client application you may want to look at ETag when making REST calls.
From the wikipedia article:
In typical usage, when a URL is retrieved the web server will return the resource along with its corresponding ETag value, which is placed in an HTTP "ETag" field:
The client may then decide to cache the resource, along with its ETag. Later, if the client wants to retrieve the same URL again, it will send its previously saved copy of the ETag along with the request in a "If-None-Match" field.
On this subsequent request, the server may now compare the client's ETag with the ETag for the current version of the resource. If the ETag values match, meaning that the resource has not changed, then the server may send back a very short response with an HTTP 304 Not Modified status. The 304 status tells the client that its cached version is still good and that it should use that.
However, if the ETag values do not match, meaning the resource has likely changed, then a full response including the resource's content is returned, just as if ETags were not being used. In this case the client may decide to replace its previously cached version with the newly returned resource and the new ETag.
Example using curl:
RESPONSE HEADER IS:
RESPONSE HEADER IS:
We see that both the ETag are same and hence the client knows that the response would be the same and can save bandwidth.
After some days, if Darius's records have not been updated then, the client can send the ETag and check for modifications:
From the 304 Not Modified, we know that the records are the same and the client doesn't have to get the data again.