Locust Directory

Basic API Load Test Example

Load test a REST based HTTP API with Bearer token authentication

Overview

Included is the test we use for load testing the LoadForge API. We use a Bearer token for authentication which you can see being set in the on_start startup definition, and then several GET requests to fetch data from our API.

Tip! Remember to disable API rate limits on your token, or you will get loads of failures :)

We have a more advanced API test example available as well.

Code

from locust import HttpUser, task, between

class QuickstartUser(HttpUser):
    wait_time = between(5, 9)
    
    def on_start(self):
        self.client.headers.update({'Authorization': 'Bearer xxx'})

    @task(1)
    def index_page(self):
        self.client.get("/api/hosts")
        self.client.get("/api/tests")
        self.client.get("/api/result/1488")
        self.client.get("/api/result/1463")          


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.