RestHelper: extension should override accept header for json / xml detection #942

Closed
tackley opened this Issue Mar 18, 2011 · 1 comment

3 participants

@tackley

I'm experimenting with the simply lift example rest app:
https://github.com/dpp/simply_lift/blob/master/samples/http_rest/src/main/scala/code/lib/BasicWithHelper.scala,
with the latest lift 2.3-SNAPSHOT.

The Accept header detection overrides the url extension

So:
curl http://localhost:8080/simple3/item/1234
curl http://localhost:8080/simple3/item/1234.json

returns json as expected, but:

curl http://localhost:8080/simple3/item/1234.xml

also returns json. This appears to be because curl sends by default an

Accept: /
header, so to get xml you have to:

curl -H "Accept:" http://localhost:8080/simple3/item/1234.xml

to stop curl sending an Accept header.

Experience with our api (http://content.guardianapis.com) is that developers always get the extension right, but are not so good at getting Accept headers right... And I always test an api with curl
before writing any code, I guess other people do too, so the curl use case is particularly confusing.

[The background: content.guardianapis.com is implemented in scala with Guice and plain servlets. I'm considering moving the code to use RestHelper.]

Is it possible to make the extension, if provided and valid, always override the accept headers?

@dpp dpp was assigned Mar 1, 2012
@etorreborre etorreborre pushed a commit to etorreborre/framework that referenced this issue Dec 3, 2014
@dpp dpp Fixes #942. json and xml requests do not match */* as documented 655789c
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment