NatLibFi / voyager-http-api

RESTful HTTP API for Voyager ILS
Apache License 2.0
0 stars 0 forks source link

Data is returned as XML, but errors as JSON #3

Open natlibfi-arlehiko opened 7 years ago

natlibfi-arlehiko commented 7 years ago

Endpoint /bib/\<id> returns data with content type application/xml but errors with content type application/json. The content type should always be the same for the same HTTP resource.

Possible solutions (All are breaking changes)

Serialization both to XML and JSON

Return both errors data and errors in the same format.

JSON payload

Return a JSON payload that contain data and/or errors. The data has to be JSON serialized, but can be parsed as XML directly:

{
  "errors": [],
  "data": "<?xml version=\"1.0\" encoding=\"UTF-8\"?><record>  <leader>00000cam^a2200649zi^4500</leader>  <controlfield tag=\"001\">000007000</controlfield>  <controlfield tag=\"003\">FI-MELINDA</controlfield>  <controlfield tag=\"005\">20170310141457.0</controlfield>  <controlfield tag=\"008\">851112s1984^^^^ru^|||||||||||||||||fin||</controlfield>  <datafield tag=\"015\" ind1=\" \" ind2=\" \">    <subfield code=\"a\">f853358</subfield>    <subfield code=\"2\">skl</subfield>  </datafield>  <datafield tag=\"035\" ind1=\" \" ind2=\" \">    <subfield code=\"a\">(FI-MELINDA)000007000</subfield>  </datafield>  <datafield tag=\"040\" ind1=\" \" ind2=\" \">    <subfield code=\"a\">FI-NL</subfield>  </datafield>  <datafield tag=\"041\" ind1=\"1\" ind2=\" \">    <subfield code=\"a\">fin</subfield>    <subfield code=\"h\">rus</subfield>  </datafield>  <datafield tag=\"042\" ind1=\" \" ind2=\" \">    <subfield code=\"a\">finb</subfield>  </datafield>  <datafield tag=\"080\" ind1=\" \" ind2=\" \">    <subfield code=\"a\">338.439</subfield>    <subfield code=\"x\">(47+57)</subfield>    <subfield code=\"9\">FENNI&lt;KEEP&gt;</subfield>  </datafield>  <datafield tag=\"130\" ind1=\"0\" ind2=\" \">    <subfield code=\"a\">Vsenarodnoe delo.</subfield>  </datafield>  <datafield tag=\"245\" ind1=\"0\" ind2=\"0\">    <subfield code=\"a\">asdasdasd FOO kansan asia :</subfield>    <subfield code=\"b\">Neuvostoliiton elintarvikeohjelman toteuttaminen /</subfield>    <subfield code=\"c\">[suom. Pekka Forsstedt].</subfield>  </datafield>/record>"
}
petuomin commented 7 years ago

I would suggest that we fix the issue by defining and returning the error types also in XML. I suppose that will break some client library then? Is it reasonable to expect changes to the client libraries?

To help fixing the client libraries, we could move the current behaviour under some new content-type (something like application/xml+json-errors or application/legacy or something) and then implement application/xml so that it always returns XML responses. That way the client libraries should only change the request content-type.

natlibfi-arlehiko commented 7 years ago

Yeah. Using a different content type for the old behaviour sounds reasonable. Setting that header on the client side will be a minor change in all known clients.