Skip to main content

REST APIs

DrevOps\BehatSteps\Steps\Web\RestTrait - Source, Example, Helpers

Test REST APIs with lightweight steps.

  • Set HTTP headers for subsequent requests.
  • Send requests with any HTTP method (GET, POST, PUT, PATCH, DELETE).
  • Assert response status codes and body content.

Skip processing with tag: @behat-steps-skip:RestTrait.

Options​

OptionTypeDefaultTagDescription
rest.enabledbooleanTRUE@behat-steps-skip:RestTraitReset the request state this trait accumulates between scenarios.

Steps​

@Given the REST header :name has the value :value

Set a REST header for subsequent requests

Given the REST header "Accept" has the value "application/json"
Given the REST header "Authorization" has the value "Bearer abc123"
@When I send a REST :method request to :url

Send a REST request to a URL

When I send a REST "GET" request to "/api/resource"
When I send a REST "DELETE" request to "/api/resource/1"
@When I send a REST :method request to :url with the body:

Send a REST request to a URL with a body

When I send a REST "POST" request to "/api/resource" with the body:
"""
{"name": "example"}
"""
@Then the REST response status code should be :code

Assert the REST response status code

Then the REST response status code should be 200
Then the REST response status code should be 404
@Then the REST response should contain :value

Assert the REST response contains text

Then the REST response should contain "success"