0
0
Rest APIprogramming~30 mins

Load testing in Rest API - Mini Project: Build & Apply

Choose your learning style9 modes available
Load Testing a REST API
📖 Scenario: You work as a developer testing a simple REST API that returns user data. You want to check how the API behaves when many requests are sent quickly.
🎯 Goal: Build a small program to send multiple requests to the API and count how many succeed.
📋 What You'll Learn
Create a list of URLs to test
Set a variable for the number of requests to send
Use a loop to send requests and count successful responses
Print the total number of successful requests
💡 Why This Matters
🌍 Real World
Load testing helps check if an API can handle many users or requests at once without slowing down or crashing.
💼 Career
Developers and testers use load testing to ensure web services are reliable and perform well under pressure.
Progress0 / 4 steps
1
Create the list of API URLs
Create a list called api_urls with these exact URLs: "https://jsonplaceholder.typicode.com/users/1", "https://jsonplaceholder.typicode.com/users/2", and "https://jsonplaceholder.typicode.com/users/3".
Rest API
Need a hint?

Use square brackets [] to create a list and include the URLs as strings inside.

2
Set the number of requests
Create a variable called num_requests and set it to 5 to represent how many times you will send requests to each URL.
Rest API
Need a hint?

Just write num_requests = 5 on a new line.

3
Send requests and count successes
Import the requests module. Create a variable called success_count and set it to 0. Use nested for loops: the outer loop uses _ to repeat num_requests times, the inner loop uses url to go through api_urls. Inside the inner loop, send a GET request to url using requests.get(url). If the response status code is 200, increase success_count by 1.
Rest API
Need a hint?

Remember to import the requests module first. Use two loops: one for the number of requests, one for each URL.

4
Print the total successful requests
Write a print statement to display the text "Total successful requests:" followed by the value of success_count using an f-string.
Rest API
Need a hint?

Use print(f"Total successful requests: {success_count}") to show the result.