<- Test Directory

Post with JSON data

Send an HTTP POST request with a JSON data payload


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)

    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)

This guide is part of the LoadForge Directory, an index of locustfile's for use with LoadForge website and API load tests. We also provide a wizard to generate tests, and onboarding assistance for clients. Contact us should you have any questions.

LoadForge provides load testing and stress tests for websites, APIs and servers. It uses your cloud account to rapidly scale large numbers of simulated users to load test your website, store, API, or application for cheap - just cents per test!

For more help on Tests please see our official documentation. Logged in users can also use our wizard to generate a locustfile, or you can record your browser steps.

Ready to run your test?
Start your first test within minutes.