Sending POST requests is very easy using LoadForge. With JSON data you need to apply a small amount of parsing to it before you post. The below example will submit a simple payload to a URL.
You will see we use json.dumps(payload) to process the payload array, and we set the header Content Type to application/json.
import time, json
from locust import HttpUser, task, between
class QuickstartUser(HttpUser):
wait_time = between(3, 5)
@task(1)
def api_page(self):
payload = {
'key': 'value'
'question': 'answer123'
}
headers = {'content-type': 'application/json'}
response = self.client.post("/post/endpoint", data=json.dumps(payload), headers=headers)