RestHelper: extension should override accept header for json / xml detection
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
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?
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?
Leave a comment