POST request with wrk?

for those looking for a content-type "application/json" example:

wrk.method = "POST"
wrk.body = '{"firstKey": "somedata", "secondKey": "somedata"}'
wrk.headers["Content-Type"] = "application/json"

This is possible now. Here is an example https://github.com/wg/wrk/blob/master/scripts/post.lua.

wrk.method = "POST"
wrk.body   = "foo=bar&baz=quux"
wrk.headers["Content-Type"] = "application/x-www-form-urlencoded"

save this in a *.lua script and pass it into your command line test with the -s flag.


I'll recommend using wrk2 instead of wrk since wrk2 provides better support for concurrent requests. When content-type header is application/json then please escape the special characters like \n with \\n and all other special characters present. Not doing this will send an invalid json to the upstream API, which will waste your time debugging.

Create a file with extension lua and paste the following in it. Save it and pass it along with -s flag to wrk2 command.

wrk.method = "POST"
wrk.body = "{\"firstKey\": 'somedata', \"secondKey\": 'somedata'}"
wrk.headers["Content-Type"] = "application/json"

Also you can add multiple header as

wrk.headers["Header1"] = "Header1_Val"
wrk.headers["Header2"] = "Header2_Val"
wrk.headers["Header3"] = "Header3_Val"
wrk.headers["Header4"] = "Header4_Val"
wrk2 -t500 -c1000 -d160s -R10000 -s ~/Documents/luaTestScript.lua http://localhost:8080/test_endpoint