According to the HTML4 reference there's no attribute to pass on HTTP headers using the anchor tag.
I would like to offer a link requesting for a specific file type using the Accept
header.
The only way I can see is simply let it be, and pass a GET
parameter.
You may as why I would want to do this... I intend to expose a bunch of methods as a public API, serving the results as JSON
. And when doing requests using JavaScript, or another programming language, using the Accept
header to request a specific response format is "The Right Way" to do it. But that would mean that I need to accommodate both the Accept
header and the GET
parameter in my code, which smells like a duplication of logic.
This topic is largely debatable, as such links may not be possible to bookmark in the browser... still... I'd like to know if it was possible without too much magic...
I don't see another way than using the GET parameter or an extension like
http://myurl/page?format=json
or better
http://myurl/page.json
Which overrides the accept header (since the browser will only send it's default accept header). Then you just need to initialize a format to accept header mapping like this (which I don't find duplicate logic at all):
{
"json" : "application/json",
"html" : "text/html"
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With