๐Ÿงช

Using Postman for API Testing

Jul 4, 2024

Using Postman for API Testing

Introduction

  • Postman: Popular tool for testing various APIs.
  • Tutorial covers:
    • Sending different types of requests.
    • Sending images/videos for testing.
    • Tips for managing API structure.

Installation

  • Download Postman from postman.com and install it.
  • For simple API tests, consider using RapidAPI extension for VS Code.

Getting Started

  1. Open Postman.
  2. Options: Sign in, create a free account, or skip.
  3. Create a new folder or collection:
    • Click the plus icon, name your project, and save all APIs in this collection.

Creating Requests

  • To create a request:
    • Click the three dots on your collection.
    • Select 'Add Request'.
    • Name the request (e.g., Fetching Books Data).

Testing APIs

  • Example using Simple Book API (GET request):
    1. Copy URL and paste it into Postman.
    2. Append /books to the URL.
    3. Select GET method from the dropdown.
    4. Click 'Send' or press Ctrl + Enter (Windows) / Cmd + Enter (Mac).
    5. View response details (status code, time, size, etc.).
    6. Options to preview and save the response.

Sending Data with Requests

Query Parameters

  • Open the Params tab and write your parameters.
  • Example: Filter books by type (e.g., fiction).

Path Parameters

  • Create a request for single book details:
    • Use path parameters for book ID.
    • Syntax: /books/:bookId (Postman auto-adds path parameter fields).
    • Pass value and click 'Send'.
    • Alternatively, directly append the ID to the URL.

POST Requests

  • Create a new POST request for login:
    • Define the URL and select POST method.
    • In the Body section, select the appropriate data format (e.g., raw, JSON).
    • Pass JSON data (email, password).
    • Click 'Send' to see the response.

Sending Headers

  • Use the Headers section:
    • Add data in key-value pairs (e.g., JSON Web Token).

Sending Files (Images/Videos)

  • Go to Body section and select form-data.
  • Define variable name and choose data type (file/text).
  • Example: Send video file.

Customization

  • Click the settings icon:
    • General tab: Change font size, font style, etc.
    • Theme tab: Select dark or light theme.

Conclusion

  • Postman is user-friendly for API testing.
  • Reach out for doubts in the comment section.