Spring-cloud-netflix: Counterintuitive how spring-feign client is behaving for produces/consumes being mapped to Accept/Content-Type headers

Created on 1 Nov 2017  路  4Comments  路  Source: spring-cloud/spring-cloud-netflix

@FeignClient(name = "sample-service")
public interface SampleFeignClient {

    @RequestMapping(method = RequestMethod.GET, value = "/sample-service/sample",
            produces = "application/xml",
            consumes = "text/xml")
    String getSample();
}

I see that on Http Request the headers are as follows:

  1. Accept: application/xml (as defined on "produces" attribute)
  2. Content-Type: text/xml (as defined on "consumes" attribute)

This seems counterintuitive to me, I'd expect the following:

  1. Accept: text/xml (as defined on "consumes" attribute, since this is what should indicate what media type client can consume in response from service)
  2. Content-Type: application/xml (as defined on "produces" attribute, since this is type of content client can produce, as a way to indicate to service on type of request to expect)

Thoughts...?

question

All 4 comments

Another reason I should have never added the Spring MVC annotations to feign :-) They map to the same headers as the server. It means the server 'consumes' text/html, so the client creates the Content-Type header. People share interfaces between client and server. I don't think this will change.

I see the motivation :) however sharing interfaces between client and server does not seem like a great idea especially when using consumes and produces attributes.

Also Http headers on Server have a completely different meaning:

  1. Accept: indicates what type of request it can consume from client (hence rightly mapped to "consumes" on server)
  2. Content-Type: indicates what type response it'll generate (rightly mapped to "produces" on server)
    @RequestMapping(value = "/sample-service/sample",
            produces = "text/xml",
            consumes = "application/xml"
    )
    public ResponseEntity<String> sample() {
        return ResponseEntity.ok("sample response");
    }

Below is a little visual that sums up our conversation - on my original expectation when I started looking at spring-feign and how it actually turned out to be :)

Expected (intuitive)
spring-feing intuitive

Existing (not so intuitive)
spring-feing counterintuitive

Anyways thank you Spencer for quick response! I understand the motivation and something we need to keep in mind as we use spring-feign.

Closing due to age of the question. If you would like us to look at this issue, please comment and we will look at re-opening the issue.

Was this page helpful?
0 / 5 - 0 ratings