Wiki Spaces
Documentation
Projects
Resources
Get Help from Others
Q&A: Ask OpenMRS
Discussion: OpenMRS Talk
Real-Time: IRC Chat | Slack
Prior to reading this page, it is important to have an understanding of the API from a non-technical point of view. First read the REST Web Services API For Clients page before going through this one.
These pages exist to help a developer walk through creating a new ws. They might be more helpful to some devs than this page:
Adding a Web Service Step by Step Guide for Core Developers
Adding a Web Service Step by Step Guide for Module Developers
When a user calls
GET /openmrs/ws/rest/v1/patient/939921-32-DA-32342
, this is the order of actions performed:
MainResourceController has the retrieve GET method, which reads resource and uuid from the url.
@RequestMapping(value = "/{resource}/{uuid}", method = RequestMethod.GET) @ResponseBody public Object retrieve(@PathVariable("resource") String resource, @PathVariable("uuid") String uuid, HttpServletRequest request)
curl -i -u admin:test http://localhost:8080/openmrs/ws/rest/v1/patient?q=987654321
echo '{"name":"Darius Patients", "description":"Created by Web Service"}' | curl -i -u admin:test -H "Content-type: application/json" -X POST -d @- http://localhost:8080/openmrs/ws/rest/v1/cohort
echo '{"patient":"5ee9b94c-81f8-4c15-96ec-c1aa9c0b0d66"}' | curl -i -u admin:test -H "Content-type: application/json" -X POST -d @- http://localhost:8080/openmrs/ws/rest/v1/cohort/0bbc73bd-0986-4581-9d3a-87cdeea13251/members
curl -i -u admin:test http://localhost:8080/openmrs/ws/rest/v1/cohort/0bbc73bd-0986-4581-9d3a-87cdeea13251/members
curl -i -u admin:test http://localhost:8080/openmrs/ws/rest/v1/cohort/0bbc73bd-0986-4581-9d3a-87cdeea13251
echo '{ "patient":"5ee9b94c-81f8-4c15-96ec-c1aa9c0b0d66", "encounterDatetime":"2011-02-18", "location":"Unknown Location", "encounterType":"ADULTINITIAL", "provider":"5ee9b94c-81f8-4c15-96ec-c1aa9c0b0d66" }' | curl -i -u admin:test -H "Content-type: application/json" -X POST -d @- http://localhost:8080/openmrs/ws/rest/v1/encounter
echo '{ "patient":"5ee9b94c-81f8-4c15-96ec-c1aa9c0b0d66", "encounterDatetime":"2011-02-18", "location":"Unknown Location", "encounterType":"ADULTINITIAL", "provider":"5ee9b94c-81f8-4c15-96ec-c1aa9c0b0d66", "obs": [ { "concept":"WEIGHT", "value":"70" } ] }' | curl -i -u admin:test -H "Content-type: application/json" -X POST -d @- http://localhost:8080/openmrs/ws/rest/v1/encounter
echo '{ "encounterDatetime":"2011-02-19" }' | curl -i -u admin:test -H "Content-type: application/json" -X POST -d @- http://localhost:8080/openmrs/ws/rest/v1/encounter/403a41ac-8f5e-45a0-976c-45303ab3aa4d
echo '{ "preferredIdentifier":{ "identifier":"abc123ez", "identifierType":"8d79403a-c2cc-11de-8d13-0010c6dffd0f", "location":"Unknown Location"}, "preferredName":{ "givenName":"Darius", "familyName":"Programmer"}, "birthdate":"1978-01-15", "gender":"M" }' | curl -i -u admin:test -H "Content-type: application/json" -X POST -d @- http://localhost:8080/openmrs/ws/rest/v1/patient
When using curl with multiple request parameters, you might note occurrences where the application fails to identify anything other than the very first request parameter in the url.
This is because request parameters are separated by the & (ampersand character)
This character may signify that any commands which follow immediately behind should be executed simultaneously.
The only way to avoid such a situation is to surround your entire URL with a double quote (" "). Doing so will resolve the above error.
Please suggestion topic headings for other devs to fill in...