0
0
Postmantesting~5 mins

Example requests and responses in Postman

Choose your learning style9 modes available
Introduction

Example requests and responses help you understand how an API works by showing what to send and what to expect back.

When you want to test if an API endpoint works correctly.
When you need to learn how to use a new API.
When you want to share how to use an API with your team.
When you want to check if the API returns the right data.
When you want to automate tests for an API.
Syntax
Postman
GET /api/users HTTP/1.1
Host: example.com

Response:
HTTP/1.1 200 OK
Content-Type: application/json

{
  "users": [
    {"id": 1, "name": "Alice"},
    {"id": 2, "name": "Bob"}
  ]
}

The request shows the method (GET), the URL path (/api/users), and headers.

The response shows the status code (200 OK), headers, and the JSON data returned.

Examples
This example shows a POST request to login with username and password, and the response returns a token.
Postman
POST /api/login HTTP/1.1
Host: example.com
Content-Type: application/json

{
  "username": "user1",
  "password": "pass123"
}

Response:
HTTP/1.1 200 OK
Content-Type: application/json

{
  "token": "abc123xyz"
}
This example shows a GET request for a product that does not exist, returning a 404 error with a message.
Postman
GET /api/products/5 HTTP/1.1
Host: example.com

Response:
HTTP/1.1 404 Not Found
Content-Type: application/json

{
  "error": "Product not found"
}
Sample Program

This is a simple example of a GET request to fetch a list of books and the expected JSON response with book details.

Postman
GET /api/books HTTP/1.1
Host: example.com

Response:
HTTP/1.1 200 OK
Content-Type: application/json

{
  "books": [
    {"id": 101, "title": "Learn Testing"},
    {"id": 102, "title": "API Basics"}
  ]
}
OutputSuccess
Important Notes

Always check the status code to know if the request was successful.

Use clear and simple example data to make understanding easier.

Include both request and response to show the full interaction.

Summary

Example requests and responses show how to use an API step-by-step.

They help you test and understand API behavior.

Clear examples make teamwork and learning faster.