DEV Community

Cover image for When I send a METHOD request to "endpoint"
webship.co
webship.co

Posted on

When I send a METHOD request to "endpoint"

API testing is a crucial step to ensure that web systems and applications function smoothly.
It involves sending different types of requests to specific API endpoints, such as GET, POST, PUT, or DELETE, to verify the server’s response and data accuracy.

The core of every API test is the step:

When I send a METHOD request to 'endpoint'

This step definition is used to send an HTTP request (GET, POST, PUT, DELETE, etc.) to a given API endpoint. It’s the action step that actually makes the call using the data, headers, and base URL you’ve set in previous steps.

Tells the test to make an HTTP request using the chosen method (GET, POST, PUT, DELETE…) to the specified path.

Example #1: When I send a GET request to "/users"
Example #2: When I send a POST request to "/posts"
Example #3: When I send a PUT request to "/users/1"
Example #4: When I send a DELETE request to "/posts/1"

Real Testing Context

We’ll use the GET method to test the /node/blog endpoint in Drupal CMS, ensuring it responds successfully with a status code of 200.

Feature: API Functional Testing for Drupal CMS Blog Endpoint
  This feature demonstrates how to test the API endpoint for blog content.
  It focuses on sending a GET request to the blog node and checking the response status.

  Background:
    Given the API base URL is "http://localhost/test/drupalCMS/web/api/v1"

  Scenario: Check the blog node API response
    Given I am on "/api/v1"
     When I send a GET request to "/node/blog"
    Given I am on "/api/v1/node/blog"
     Then the API response code should be 200
Enter fullscreen mode Exit fullscreen mode

See the full article: https://webship.co/blog/when-i-send-method-request-endpoint

Automated testing not only saves time but also prevents human errors, helping catch issues before they ever reach the end user.
And while it’s a serious process, testing can sometimes feel like a playful challenge with code: you send a request, wait for the response, and either smile when it works… or laugh when it fails.

Top comments (0)