Using Apache Bench (ab) to POST JSON to an API
Apache bench is a popular load testing application. But how do you use it to test an API that accepts a JSON payload using the POST method?
You can use the following command:
ab -p json.txt -T application/json -H 'Authorization: Token abcd1234' -c 10 -n 2000 http://example.com/json/api
json.txtcontains the json you want to post
-pmeans to POST it
-Hadds an Auth header (could be Basic or Token)
-Tsets the Content-Type
-cis concurrent clients
-nis the number of requests to run in the test
You can try adding the
-l key to accept dynamic response length if there are lots of failed requests.