=== modified file 'src/docbkx/en/dhis2_user_man_web_api.xml' --- src/docbkx/en/dhis2_user_man_web_api.xml 2012-03-19 20:15:48 +0000 +++ src/docbkx/en/dhis2_user_man_web_api.xml 2012-03-20 20:23:52 +0000 @@ -4,7 +4,7 @@ Web API The Web API is a component which makes it possible for external systems to access and manipulate data stored in an instance of DHIS 2. More precisely, it provides a programmatic interface to a wide range of exposed data and service methods for applications such as third-party software clients, web portals and internal DHIS 2 modules.
- Basics + Introduction The Web API adheres to many of the principles behind the REST architectural style. To mention some few and important ones: @@ -82,4 +82,13 @@ curl -d "Yes the Mortality data set has been reported" "http://apps.dhis2.org/demo/api/messageConversations/ZjHHSjyyeJ2" -H "Content-Type:text/plain" -u mobile:district -X POST -v If all went according to plan you will receive a 200 OK status code.
+
+ Example: Embedding reports in web pages + In this example we will see how we can build a simple web page where dynamic data such as tabular reports and charts is pulled from the DHIS Web API. + The Web API contains several resources which are useful for data analysis: report, reportTable, chart, map and document. Dispatching GET requests to the mentioned URLs will return the relevant meta-data information for each resource. For all of those resources it is valid to append /data to the URL. The response such GET-requests will convey information about the aggregated data related to the resource. This information can be represented in a variety of formats including HTML, PDF, Excel, PNG and Jasper, as we will see later. + We begin as usual at the Web API entrypoint at . We look for a relevant tabular report by following the reportTables link to . From this list we decide that we are interested in the "District Maternal Health" report and follow the link to . This resource provides meta-data information about the report table. It also advertises a link for retrieving analytical data which can be constructed by appending /data to the URL. Following this link will lead us to . As we can see we are provided with a report table in HTML format, which is the default representation format. + As stated in the introduction there are three ways of indicating which resource representation format you want for the response. The easiest alternative when used directly in web pages is to append a file suffix to the URL. We assume that we are interested in the PDF representation and indicate that by appending .pdf to our URL: . Go ahead and try out all valid extensions for this resource which are .html, .pdf, .xls and .csv. + Also note that the report table can be parameterized with an organisation unit and a period by supplying a ou and pe query parameter together with an organisation unit identifier and period string respectively in the URL. If not provided the Web API will use the top-most organisation unit in the hierarchy and the last time period for the report table content. The organisation unit identifier can be looked up by going to the Web API entrypoint, following the link to the organisationUnits resouce. For our example we will request that Bo district whith identifier O6uvpzGd5pu is used as the organisation unit: . + Autenticating to a DHIS instance from a web page can be done in many ways, and each method has advantages and downsides. +