Load Testing with HTTP POST Requests in Locust
Understanding HTTP POST in Load Testing
Example: Performing POST Requests with Locust
from locust import HttpUser, constant, task
import uuid
class MyReqRes(HttpUser):
wait_time = constant(1) # Wait 1 second between tasks
host = "http://localhost:8001" # Base URL for the API
@task
def get_todos(self):
# GET request to retrieve a specific todo item
res = self.client.get("/todos/104")
print(res.text)
@task
def create_todos(self):
# Generate a unique ID and create a todo item
request = {
"id": str(uuid.uuid4()),
"name": "Meet at 9 AM",
"description": "Need to meet client at 9 AM tomorrow"
}
# POST request to create a new todo
res = self.client.post("/todos", json=request)
print(res.text)
Explanation of the Code
PreviousHTTP Load Testing with Locust's HttpUserNextUsing catch_response in Locust for Custom Response Validation
Last updated