← Back to team overview

dhis2-devs-core team mailing list archive

WebMessage

 

Hei everyone

A few days again, I committed a new class called WebMessage. The point of
this class is to have a common building block for all kind of responses
from the web-api.

The main properties are:
WebMessage:
  status: OK / ERROR
  code: internal code
  httpStatusCode: http status code
  message: non-technical end-user message (i18n etc)
  devMessage: technical / debug message
  response: WebMessageResponse, can be anything

So a typical response can be:

JSON:
{
  status: "OK",
  code: 20001,
  httpStatusCode: 200 // notice that code also starts with 200
  message: "DataElement successfully saved.",
  devMessage: "DataElement was successfully saved to database, id ID123"
}

XML:
<webMessage xmlns="http://dhis2.org/schema/dxf/2.0"; status="OK"
code="20001" httpStatusCode="200">
  <message> DataElement successfully saved .</message>
  <devMessage> DataElement was successfully saved to database, id ID123
</devMessage>
</webMessage>

And of course, response can be added... its just a simple interface, with
nothing on it. so you can create your own implementations (I only provide
one, ImportCountWebMessageResponse)

This class is not currently in use, but I'm planning to implement this
full-scale in 2.18, so I'm very open to any kind of comments (unless you
are living under a rock, you will be starting to see this messages all the
time), so please.. this is the time to change this format (it will be fixed
from 2.18).

Comments?

httpStatusCode can definitely be left out, but it just simplifies things a
lot to leave it in..

--
Morten

Follow ups