batch-requests

This improves the performance significantly in cases where the client needs to access multiple APIs.

note

The HTTP headers for the outer batch request (except for Content- headers like Content-Type) apply to every request in the batch.

If the same HTTP header is specified in both the outer request and on an individual call, the header of the individual call takes precedence.

Attributes

None.

API

This plugin adds /apisix/batch-requests as an endpoint.

batch-requests - 图2note

You can enable the batch-requests Plugin by adding it to your configuration file (conf/config.yaml):

conf/config.yaml

Configuration

By default, the maximum body size that can be sent to /apisix/batch-requests can’t be larger than 1 MiB. You can change this configuration of the Plugin through the endpoint apisix/admin/plugin_metadata/batch-requests:

  1. curl http://127.0.0.1:9080/apisix/admin/plugin_metadata/batch-requests -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
  2. "max_body_size": 4194304
  3. }'

Metadata

This plugin will create an API endpoint in APISIX to handle batch requests.

HttpRequest

Response

The response is an array of HttpResponses.

HttpResponse

Specifying a custom URI

You can set the URI you want when creating the Route and change the configuration of the public-api Plugin:

Example usage

First, you need to setup a Route to the batch request API. We will use the public-api Plugin for this:

  1. curl http://127.0.0.1:9080/apisix/admin/routes/br -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
  2. {
  3. "uri": "/apisix/batch-requests",
  4. "plugins": {
  5. }
  6. }'

Now you can make a request to the batch request API (/apisix/batch-requests):

This will give a response:

  1. [
  2. {
  3. "status": 200,
  4. "reason": "OK",
  5. "body": "{\"ret\":500,\"msg\":\"error\",\"game_info\":null,\"gift\":[],\"to_gets\":0,\"get_all_msg\":\"\"}",
  6. "headers": {
  7. "Connection": "keep-alive",
  8. "Date": "Sat, 11 Apr 2020 17:53:20 GMT",
  9. "Content-Length": "81",
  10. "Server": "APISIX web server"
  11. }
  12. {
  13. "status": 200,
  14. "reason": "OK",
  15. "body": "{\"ret\":500,\"msg\":\"error\",\"game_info\":null,\"gift\":[],\"to_gets\":0,\"get_all_msg\":\"\"}",
  16. "headers": {
  17. "Connection": "keep-alive",
  18. "Date": "Sat, 11 Apr 2020 17:53:20 GMT",
  19. "Content-Type": "application/json",
  20. "Content-Length": "81",
  21. "Server": "APISIX web server"
  22. }
  23. }
  24. ]

You can remove batch-requests from your list of Plugins in your configuration file (conf/config.yaml).