Response formats
Every endpoint returns JSON by default. The same data is also available as XML through standard HTTP content negotiation — useful when your application already speaks XML. The response body is identical in shape; only the serialization changes.
Asking for XML
Two ways, in priority order:
Accept: application/xml— the standard mechanism.?format=xml— an explicit query-param override, handy in a browser or a quick curl.?format=jsonforces JSON even whenAcceptasks for XML.
With no Accept header, Accept: */*, or
Accept: application/json, you get JSON exactly as before —
existing integrations are unaffected.
XML shape
The serializer is small and predictable. The document root is
<response>; object keys become elements; arrays
become repeated <item> elements wrapped in the
parent key. Text is XML-escaped.
From the SDKs
The typed resource methods (laws.retrieve, …) always
return JSON-parsed models. To get the raw XML for any endpoint, use
the low-level request_raw primitive — it sets the format
and hands you the body untouched.
request_raw defaults to format="xml", so the
examples above already negotiate XML. Pass format="json"
to fetch a raw JSON body the same way.
Errors
Error responses honor the same negotiation: if you asked for XML, a
404 or 401 comes back as XML with the same
envelope (error, message, detail).
Vary: Accept, so any cache or CDN keeps the two
representations of a URL separate and never serves the wrong one.