Introduction

API testing is an essential part of ensuring backend functionality and data integrity within applications. This course covers the four main HTTP methods used in API testing: PUT, POST, GET, and DELETE. Using Postman, a popular API testing tool, you’ll learn how to construct and send requests, verify responses, and understand how each method serves a different purpose in CRUD operations.

API tests target the integration between software components and verify data exchange between back-end services. API tests are fast and help ensure the correctness of data handling but don’t involve the front-end interface.


1. HTTP Methods Overview

  • GET: Retrieve data from the server. For example, fetching a list of users.
  • POST: Submit new data to the server. This method is commonly used to create new resources, such as adding a new user.
  • PUT: Update an existing resource. It replaces the current representation of the target resource with the provided data.
  • DELETE: Remove data from the server. This action is used to delete resources, such as removing a user.

2. Setting Up Postman

  1. Download and Install Postman: Visit Postman to download the latest version.
  2. Create a New Request: Open Postman, then click on New > Request. You can name your request and add it to a collection.
  3. Enter the API Endpoint: In the request setup, enter the URL for the API you’re testing.

3. API Testing Example

To demonstrate each method, we’ll use a sample endpoint, assuming the base URL https://jsonplaceholder.typicode.com (a popular mock API for testing).

A. GET Request

  1. Set up the GET Request:
    • URL: https://jsonplaceholder.typicode.com/posts/1
    • This request fetches data from the server for the post with ID 1.
  2. Send the Request:
    • Click on Send. You should see a JSON response with the details of the post.
  3. Validate the Response:
    • Verify that the response status is 200 OK and contains expected data.

B. POST Request

  1. Set up the POST Request:
    • URL: https://jsonplaceholder.typicode.com/posts
    • Method: POST
    • Body: Choose raw and select JSON format.
    {
      "title": "foo",
      "body": "bar",
      "userId": 1
    }
    
  2. Send the Request:
    • Click on Send. You should see a response with a 201 Created status code and the new resource in the response.
  3. Validate the Response:
    • Check that the response contains the data you sent and a new id.

C. PUT Request

  1. Set up the PUT Request:
    • URL: https://jsonplaceholder.typicode.com/posts/1
    • Method: PUT
    • Body: Choose raw and select JSON format.
    {
      "id": 1,
      "title": "updated title",
      "body": "updated body",
      "userId": 1
    }
    
  2. Send the Request:
    • Click on Send. The response should indicate that the post has been updated.
  3. Validate the Response:
    • Confirm that the title and body in the response match the updated data.

D. DELETE Request

  1. Set up the DELETE Request:
    • URL: https://jsonplaceholder.typicode.com/posts/1
    • Method: DELETE
  2. Send the Request:
    • Click on Send. The response should show a 200 OK or 204 No Content status code.
  3. Validate the Response:
    • Verify that the resource was deleted by sending another GET request to the same URL. You should receive a 404 Not Found response.

4. Summary

In this course, you learned the fundamental HTTP methods for API testing using Postman. Each method plays a specific role in interacting with server resources:

  • GET to retrieve data
  • POST to create new data
  • PUT to update existing data
  • DELETE to remove data

With these methods and Postman, you have the tools to test and validate API behavior, ensuring that it meets your application’s requirements.


Quiz: API Testing Knowledge Check

  1. Which HTTP method is used to retrieve data from a server?

    • GET
    • POST
    • PUT
    • DELETE
  2. What status code is expected when a resource is successfully created?

    • 200 OK
    • 201 Created
    • 404 Not Found
    • 500 Internal Server Error
  3. What type of request would you use to update an existing resource?

    • GET
    • POST
    • PUT
    • DELETE
  4. Which method should you use to remove a resource from the server?

    • GET
    • POST
    • PUT
    • DELETE

With this knowledge, you’re now ready to begin testing APIs in Postman and understand the primary HTTP methods in CRUD operations.