When I send a METHOD request to "endpoint" with body:

Sends an HTTP request to a relative endpoint with a raw body supplied as a multi-line doc string (a block delimited by triple quotes). The method is uppercase, such as POST or PUT, and the endpoint is appended to the API base URL. Placeholders in the body are replaced before sending.

If the body parses as JSON, it is sent as JSON and a Content-Type: application/json header is added automatically unless you already set one; otherwise the body is sent as a raw string. Any headers set earlier in the scenario are included. HTTP error statuses do not fail the step, so follow it with a response-code assertion. Use this step when you need full control over the payload; for simple key-value payloads the with-values table variant is more readable.

Accepted phrasings

When I send a METHOD request to "/endpoint" with body:
When we send a METHOD request to "/endpoint" with body:
When send a METHOD request to "/endpoint" with body:

Examples

When I send a POST request to "/users" with body:
When we send a POST request to "/posts" with body:
When I send a PUT request to "/users/1" with body:
When we send a POST request to "/contacts" with body:

In a real scenario

Feature: Creating content through the API

  Scenario: A new post is created with a JSON payload
    Given the API base URL is "https://api.example.org"
      And I set header "Authorization" to "Bearer {{token}}"
     When I send a POST request to "/posts" with body:
          """
          {
            "title": "Welcome",
            "body": "First post on the portal",
            "userId": 1
          }
          """
     Then the API response code should be 201
      And the API response should contain "Welcome"

Related steps

Back to Api Steps