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
3
votes
1 answer

Jersey - content negotiation for error handling

I'd like to allow clients to select an error response format using HTTP content negotiation. E.g. given an endpoint @Produces("application/json") class MyService { @GET public String getSomething() { if (currentTimeMilis() % 2 == 0) throw new…
Jakub Bochenski
  • 3,113
  • 4
  • 33
  • 61
3
votes
4 answers

Lithium content negotiation displays all data - how to filter it out?

I have app/controllers/UsersController.php that does a simple Users::find('all'); in the index action. The path /users/index renders plain 'ol HTML output of the users data. The path /users/index.json render the JSON equivalent of the HTML output…
Housni
  • 963
  • 1
  • 10
  • 23
3
votes
1 answer

Different REST-ful representations of the same Entity and content negotiation

Given the REST-ful web service /product/{product-id} that returns Product XML documents of the Content-Type x-esvc/product+xml I also need to support x-esvc/prices+xml (x-esvc is a custom MIME type; product and prices are two subtypes and +xml…
Christoffer Soop
  • 1,458
  • 1
  • 12
  • 24
3
votes
1 answer

Is it OK to have content negotiation in your controller layer?

In Zend Framework 2, content negotiation happens on the view layer and I am pretty happy with it. An example in my controller: public function viewAction() { $id = $this->params('id'); $user = $this->getRepository()->findUser(); …
3
votes
3 answers

how to use built-in content type negotiation and just get access to the decision

I wanted to take advantage of built-in content negotiator and just get access to decision what formatter is going to be used. I don't want to use Request.Headers.Accept and check for whether it is json or xml content type because there lot of…
user1186065
  • 1,847
  • 3
  • 17
  • 22
2
votes
3 answers

Spring MVC 3 content negotiation restrict to actions which support it

I have configured content negotiation in my Spring MVC 3 app as follows:
Rich
  • 15,048
  • 2
  • 66
  • 119
2
votes
1 answer

How does Grails' content negotiation handle opposing types?

Grails supports content negotiation from 3 different sources: Accept header Request parameter (format) URI extension The question is, what does it do when it get content information from more than one place, especially when they don't agree with…
cdeszaq
  • 30,869
  • 25
  • 117
  • 173
2
votes
2 answers

How to disable content negotiation and always return JSON from WCF data service?

Let's say I have a northwind database and I use ADO.NET Entity Data Model which I automatically generate from the tables in database. Then I add a new WCF data service that inherits from DataService. When I start the web application, that runs the…
Michal B.
  • 5,676
  • 6
  • 42
  • 70
2
votes
2 answers

How to set priority to Spring-Boot request mapping methods

I have a Spring-Boot (v2.0.2) application with a RestController with 2 methods which only differ by the Accept header. A simplified version of the code is this: @RestController @RequestMapping("/myapp") public class FooController { …
2
votes
1 answer

Spring Boot manual content negotiation

I'm reworking old rest api and need to keep compatibility with it. Old api uses servlets and works with both xml and json. The logic is following: it checks 'Content-Type' header, if it's supported ('text/xml', 'application/xml',…
igor
  • 179
  • 1
  • 1
  • 5
2
votes
1 answer

Which media type should be chosen from HTTP Accept header when they have the same specifity, quality and level?

As you know you can add multiple media types to the HTTP Accept header. When it comes to the question "What type should the server return?" most explanations and the spec as well seem to only explain the algorithm to select the "preferred" media…
Pipo
  • 5,623
  • 7
  • 36
  • 46
2
votes
2 answers

Why would HTTP content negotiation be preferred to explicit parameters in an API scenario?

HTTP content negotiation can be used to make client and server agree on a data format and language. Maybe you're interested in my previous question (Is HTTP content negotiation being used by browsers and servers in practice?) but it's not necessary…
boot4life
  • 4,966
  • 7
  • 25
  • 47
2
votes
2 answers

Is HTTP content negotiation being used by browsers and servers in practice?

I'm learning about HTTP content negotiation at the moment. I already understand the basic way client and server are able to negotiate a representation for the content requested. I could not find out, though, what content negotiation is actually good…
boot4life
  • 4,966
  • 7
  • 25
  • 47
2
votes
1 answer

How to Use Content Negotiation in Spring Data Rest?

I am trying to expose my data via Rest Api in difetents formats (xml,json,rdf,jsonld) and I am using Spring-Data-Rest-Framework and I know that it is posible using @RequestMapping in the Controller, buts in Spring Data Rest I only have a entity and…
2
votes
2 answers

Can you specify preferred default media type for a single path in Spring MVC?

I have a Jersey application which has been converted to Spring MVC. One piece of functionality that I don't see a way to port directly over is the ability, per path, to specify the preferred media type if none is specified. In Jersey, I could…
M. Justin
  • 14,487
  • 7
  • 91
  • 130