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.
note
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
:
curl http://127.0.0.1:9080/apisix/admin/plugin_metadata/batch-requests -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
"max_body_size": 4194304
}'
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:
curl http://127.0.0.1:9080/apisix/admin/routes/br -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
"uri": "/apisix/batch-requests",
"plugins": {
}
}'
Now you can make a request to the batch request API (/apisix/batch-requests
):
This will give a response:
[
{
"status": 200,
"reason": "OK",
"body": "{\"ret\":500,\"msg\":\"error\",\"game_info\":null,\"gift\":[],\"to_gets\":0,\"get_all_msg\":\"\"}",
"headers": {
"Connection": "keep-alive",
"Date": "Sat, 11 Apr 2020 17:53:20 GMT",
"Content-Length": "81",
"Server": "APISIX web server"
}
{
"status": 200,
"reason": "OK",
"body": "{\"ret\":500,\"msg\":\"error\",\"game_info\":null,\"gift\":[],\"to_gets\":0,\"get_all_msg\":\"\"}",
"headers": {
"Connection": "keep-alive",
"Date": "Sat, 11 Apr 2020 17:53:20 GMT",
"Content-Type": "application/json",
"Content-Length": "81",
"Server": "APISIX web server"
}
}
]
You can remove batch-requests
from your list of Plugins in your configuration file (conf/config.yaml
).