client-py
client-py copied to clipboard
Location header is ignored during create/update methods
Hi,
REST specification returns a Location header on successful POST/PATCH and has to be handled appropriately by the caller.. The create()/update() methods are successful with HTTP 201 but the response does not return the actual object reason being the Location header is ignored..
Snip from server.py->post_json()
res = self.session.get(url, headers=headers)
self.raise_for_status(res)
return res
Snip from fhirabstractresource->create()
ret = srv.put_json(self.relativePath(), self.as_json())
if len(ret.text) > 0:
return ret.json()
return None
Here fhirabstractresource is getting all the headers since it receives a Response object but ignores the response headers. The return response is always None on successful creation since REST does not return any data on success..
Thanks Trinadh.
This is what FHIR has the Prefer header for. This behavior is not implemented, happy to accept a pull request.
I was talking to one of EHR Provider on "Prefer" header and their answer is that it is not mandatory according to specs that it should be honored.. But Location header with the reference to newly created Object will always be set.. Is there a design that you have thought of how it should be handled based on whether data is present or use Location header?
Yes. If the prefer header is set to request a resource but the server doesn't return it, the client should issue a GET request on the Location header before returning. If the prefer header does not specify a resource return, no GET request should be issued. Means there must also be a nice way to set the prefer header.
The Swift client has such an implementation.
On 17 Feb 2017, at 08:21, bktrinadh [email protected] wrote:
I was talking to one of EHR Provider on "Prefer" header and their answer is that it is not mandatory according to specs that it should be honored.. But Location header with the reference to newly created Object will always be set.. Is there a design that you have thought of how it should be handled based on whether data is present or use Location header?
— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.
p.s.
In the Swift client we have a method create() that sets Prefer: return=minimal and does not return a resource, and we have createAndReturn() which sets Prefer: return=representation and which issues an additional GET request should the server not honor the Prefer header before returning.