Questions tagged [content-negotiation]

Content negotiation is a mechanism defined in the HTTP specification that makes it possible to serve different versions of a document (or more generally, a resource representation) at the same URI, so that user agents can specify which version fit their capabilities the best.

184 questions
44
votes
2 answers

HTTP Accept Header meaning

When a browser's Accept request header says something like the following: Accept: application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5 Does that mean that application/xml, application/xhtml+xml, and text/html…
mckamey
  • 17,359
  • 16
  • 83
  • 116
29
votes
2 answers

How to set the default content type in Spring MVC in no Accept header is provided?

If a request is sent to my API without an Accept header, I want to make JSON the default format. I have two methods in my controller, one for XML and one for JSON: @RequestMapping(method =…
user86834
  • 5,357
  • 10
  • 34
  • 47
28
votes
2 answers

Same/different DTO object in create, update and get rest end points?

Consider following UserDTO class and UserController exposing endpoints to create, update and get User. Having the id property in the UserDTO class does not make sense for create and update. If I use swagger or another auto generated API…
Bhushan Bhangale
  • 10,921
  • 5
  • 43
  • 71
15
votes
2 answers

Accept Language list

I would like to react to the Accept_Language that a browser sends to a website. Does anybody know where I can get a reliable list of all available Accept_Languages that the browser might send to a website? Thank you very much!
tmighty
  • 10,734
  • 21
  • 104
  • 218
13
votes
4 answers

Specify supported media types when sending "415 unsupported media type"

If a clients sends data in an unsupported media type to a HTTP server, the server answers with status "415 unsupported media type". But how to tell the client what media types are supported? Is there a standard or at least a recommended way to do…
deamon
  • 89,107
  • 111
  • 320
  • 448
13
votes
2 answers

Which CDN solutions support caching with content negotiation?

I'm serving a set of resources through content negotiation. Concretely, any URL can be represented in different formats, depending on the client's Accept header. An example of this can be seen at Facebook: curl -H "Accept: application/json"…
Ruben Verborgh
  • 3,545
  • 2
  • 31
  • 43
12
votes
2 answers

Is My Spring-MVC ContentNegotiatingViewResolver setup correctly? How can I send 404 error for unsupported media types?

I dunno if this is a valid question for this site, but I was wondering if someone experienced with the ContentNegotiatingViewResolver could look this over and let me know if I set it up correctly and well as help me send 404 messages. What I'd like…
egervari
  • 22,372
  • 32
  • 121
  • 175
12
votes
1 answer

ASPNetCore API Content negotiation not working

I'm trying to get my api set up so it will respond with with XML or JSON depending upon the Accept header. I'm following the tutorial by Shawn W: https://wildermuth.com/2016/03/16/Content_Negotiation_in_ASP_NET_Core It says to add a package to:…
12
votes
2 answers

What should be the return type of WEB API Action Method?

I am developing ASP.NET Web API using .NET Core. This Web API is going to be mainly accessed by UI application (UI will be developed using ASP.NET Core MVC) but in future API may be accessed by other applications as well. In my WEB API all methods…
LP13
  • 30,567
  • 53
  • 217
  • 400
11
votes
1 answer

Content negotiation to return HTML

After reading this blog post on how to return HTML from Web API 2 using IHttpActionResult, I wanted to somehow "wire-up" this IHttpActionResult to my ApiController based on the Accept header that is sent with request. Given controller actions that…
cvbarros
  • 1,684
  • 1
  • 12
  • 19
11
votes
3 answers

Spring MVC 3.2 - Content Negotiation for Error Pages?

To globally handle errors (such as HTTP 404's) which can occur outside of a Controller, I have entries similar to the following in my web.xml: 404 /errors/404 In my…
WayneC
  • 2,530
  • 3
  • 31
  • 44
9
votes
2 answers

Does HTTP content negotiation respect media type parameters

An HTTP request can include an Accept header, indicating the media type(s) of responses that the client will find acceptable. The server should honour the request by providing a response that has a Content-Type that matches (one of) the requested…
Raedwald
  • 46,613
  • 43
  • 151
  • 237
9
votes
3 answers

Rest Content Negotiation and Caching

I'm wondering how caching works with content negotiation based API. Since the to get a resource in XML or JSON, the URI will be the same, for example: http://example.com/bikes/mountain The service returns JSON / XML based on the Accept type header.…
Rosstified
  • 4,047
  • 2
  • 25
  • 33
8
votes
1 answer

HTTP Content Negotiation/Compression: Use Base64 with Accept-Encoding/Content-Encoding?

I'm wondering if the following idea is working against the spirit and/or letter of HTTP Content Negotiation and HTTP Compression. The Situation The HTTP Client requests a resource: HTTP GET /image.jpeg HTTP/1.1 Accept: image/jpeg The HTTP Server…
user647772
8
votes
2 answers

ASP.NET MVC 4 / Web API - insert Razor renderer for Accepts: text/html

I am creating a RESTful Web Service using ASP.NET MVC 4 Web API. For API access, I am returning JSON, though once I get everything working correctly, the content negotiation should work for XML and JSON by default. Since I am working towards a…
MikeJansen
  • 3,336
  • 3
  • 26
  • 37
1
2 3
12 13