Skip to content

Instantly share code, notes, and snippets.

@kelvinn
Created July 24, 2014 02:55
Show Gist options
  • Save kelvinn/6a1c51b8976acf25bd78 to your computer and use it in GitHub Desktop.
Save kelvinn/6a1c51b8976acf25bd78 to your computer and use it in GitHub Desktop.
Example of using Apache Bench (ab) to POST JSON to an API
# post_loc.txt contains the json you want to post
# -p means to POST it
# -H adds an Auth header (could be Basic or Token)
# -T sets the Content-Type
# -c is concurrent clients
# -n is the number of requests to run in the test
ab -p post_loc.txt -T application/json -H 'Authorization: Token abcd1234' -c 10 -n 2000 http://example.com/api/v1/locations/
@muhassinmusthafa
Copy link

Is it possible to store data from text file(in our post_loc.txt) into db using apache benchmarking command mentioned below:

ab -p post_loc.txt -T application/json -H 'Authorization: Token abcd1234' -c 10 -n 2000 http://example.com/api/v1/locations/

Do we need to specify db name or db related information to store json data in the text file ?

@muhassinmusthafa
Copy link

muhassinmusthafa commented Jul 10, 2018

JSON data in the text file not saved into db. but it shows metrics in the output.Anyone knows about this issue? How to solve ?

@JeanOsorio
Copy link

I trying to replicate this example but I always get:

ab: Could not stat POST data file (data.txt): Partial results are valid but processing is incomplete. I can't see the problem, any idea?

@claviering
Copy link

NICE

@raul1991
Copy link

raul1991 commented Jun 8, 2019

Can Apache bench support dyamic values in post request ?

@darrylyoung
Copy link

Thanks for sharing.

@bala-codenatives
Copy link

can someone share the actual post_loc.txt file. This command does not work with the json file used to post json data ?

I get Error : Could not stat POST data file (content.json/content.txt): Partial results are valid but processing is incomplete

This means it's unable to find the POST data file. specify the absolute path

@xuyuji9000
Copy link

xuyuji9000 commented Oct 18, 2021

Can Apache bench support dynamic values in post request ?

I have the same need .

According to this Changing POST data used by Apache Bench per iteration .

Maybe more specialized tool like Jmeter is a better option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment