What is the restTemplate.exchange() method for?

前端 未结 4 1204
日久生厌
日久生厌 2021-02-02 07:37

Actually what does the restTemplate.exchange() method do?

@RequestMapping(value = \"/getphoto\", method = R         


        
4条回答
  •  伪装坚强ぢ
    2021-02-02 08:23

    TL;DR: Q: What is a request-response pair called? A: An "exchange".


    The term exchange is used, almost incidentally, in the official technical documentation of HTTP to refer to an HTTP request combined with the corresponding response.

    However looking at the answers to the following questions, it is clear that while this may have represented a de facto standard for some people, many other were not aware of it, or hadn't adopted it.

    • What is a request-response pair called?
    • Name for HTTP Request+Response

    The documentation doesn't bother to mention the etymology of the name -- probably assuming that it's obvious.

    Notice, however, that there are many different RestTemplate HTTP request methods listed and only a small fraction of them are named exchange. The list is primarily made up of HTTP method-specific names such as delete, put, getForEntity, postForObject, et cetera. Technically speaking, all of these methods perform exchanges in the same sense, but the more focused convenience methods are limited to a specific subset of the possible exchange functionality and parameter+return types.

    To put it simply, the set of exchange functions are the most general/capable methods provided by RestTemplate, so you can use exchange when none of the other methods provides a complete enough parameter set to meet your needs.

    For example:

    • Sending GET request with Authentication headers using restTemplate, in which the OP has noticed that "...the only way to send Headers such as accept and Authorization is by using the exchange method..."

提交回复
热议问题