Sending Your First API Request
# CHAPTER 5
Sending Your First API Request
1. Introduction
Enough theory and interface tours—it is time to test an API! In this chapter, we will send our very first live API request using Postman. We will use a free, public API specifically designed for testing purposes. We will walk through configuring the Request Builder, clicking Send, and analyzing the data returned in the Response Viewer. This is the foundational workflow of all API testing.2. Learning Objectives
By the end of this chapter, you will be able to:- Construct a basic GET request in Postman.
- Identify the components needed for a simple API call.
- Execute the request and read the server's response.
- Analyze the JSON payload returned by the server.
- Verify the HTTP status code and response time.
3. Beginner-Friendly Explanation
Think of sending an API request like looking up a word in a dictionary. The Method is your action: "Look up". The URL is the specific dictionary and the word you want: "The English Dictionary -> 'Apple'". When you hit Send, you flip to the page. The Response is the definition of the word written on the page.In this chapter, we are going to "look up" a specific user profile from a public database. We will ask the server for "User Number 1", and the server will return User 1's name, email, and company details.
4. Real-World Examples
-
Checking Server Health: A DevOps engineer sends a simple GET request to
api.company.com/health. If the response returns{"status": "OK"}, they know the servers are online and functioning properly.
-
Fetching a Blog Post: When you visit a blog, the frontend code sends a GET request to
api.blog.com/posts/10. The API returns the title, author, and content of the post, which the browser then renders on your screen.
5. Step-by-Step Tutorials (Your First Request)
For this tutorial, we will use JSONPlaceholder (jsonplaceholder.typicode.com), a free fake API for testing and prototyping.Step 1: Open a New Request Tab
-
1.
Click the
+button near the top of the screen to open a new tab.
Step 2: Set the Method
- 1. Look at the dropdown menu on the left side of the URL bar.
- 2. Ensure it is set to GET. (GET means we want to retrieve or "read" data).
Step 3: Enter the URL
- 1. Click inside the URL bar (where it says "Enter request URL").
- 2. Type or paste the following exact address:
https://jsonplaceholder.typicode.com/users/1
Step 4: Send the Request
- 1. Click the big blue Send button on the right.
Step 5: View the Response
- 1. Look at the bottom half of the screen (the Response Viewer).
- 2. You should see a block of formatted JSON text containing data about a user named "Leanne Graham".
6. API Request Examples (What happened?)
When you clicked Send, Postman generated and sent the following raw HTTP request over the internet:*Note: Postman automatically added the Accept and User-Agent headers behind the scenes!*
7. Response Examples (Analyzing the Output)
Look closely at the Response Viewer. You need to check three things:-
1.
Status: Look at the top right of the response pane. It should say
200 OKin green. This means success.
-
2.
Time: Next to the status, it shows the latency (e.g.,
145 ms). This is how fast the server replied.
-
3.
Size: Next to time, it shows the size of the downloaded data (e.g.,
1.04 KB).
8. JSON Examples (The Payload)
In the Body tab of the Response Viewer, ensure "Pretty" is selected. You will see the JSON payload:Congratulations! You have successfully requested and received data from a REST API.
9. Testing Examples (Mental Verification)
Even without writing automated scripts yet, you just performed manual API testing.- *Did it return 200 OK?* Yes.
- *Is the ID equal to 1?* Yes.
- *Is the format valid JSON?* Yes.
10. Best Practices
- Save Your Requests: Don't lose your work! Click the "Save" button (or Ctrl+S). Name the request "Get User 1" and save it into a new Collection named "JSONPlaceholder Tests".
-
Inspect the Data: Don't just glance at the
200 OKstatus. Always scroll through the JSON body to ensure the actual data makes sense. An API might return200 OKbut give you the wrong user's data!
11. Common Mistakes
-
Typing the URL wrong: HTTP vs HTTPS matters. Missing a forward slash matters. If you type
jsonplaceholder.typicode.com/user/1(user instead of users), the server will return a404 Not Founderror. Precision is key.
-
Spaces in the URL: Avoid accidental spaces at the end of your URL (e.g.,
.../users/1). Postman usually handles this gracefully, but strict servers might reject it.
12. Mini Exercises
-
1.
Change the URL to
https://jsonplaceholder.typicode.com/users/2and hit Send. What is the name of the second user?
-
2.
Change the URL to
https://jsonplaceholder.typicode.com/users/999and hit Send. What happens? What is the Status Code?
13. Coding/Testing Challenges
Challenge 1: JSONPlaceholder also has an endpoint for "posts". Construct a GET request to fetch the blog post with ID number 5. *(Hint: Replace the wordusers with posts in the URL).*
What is the title of post 5?
14. MCQs with Answers
What HTTP Method is used by default when you open a new tab in Postman to fetch data?
If an API request is perfectly successful, what Status Code is typically displayed in green in the Response Viewer?
What format does JSONPlaceholder (and most modern REST APIs) use to return data?
15. Interview Questions
- Q: Walk me through the exact steps you take in Postman to manually verify that a specific endpoint is returning the correct user profile.
- Q: When you view the results of an API call in Postman, besides the JSON body, what two other metrics are crucial to observe? *(Answer: Status Code and Response Time).*