| layout | doc |
|---|---|
| title | REST Module - Codeception - Documentation |
For additional reference, please review the source
Module for testing REST WebService.
This module can be used either with frameworks or PHPBrowser. It tries to guess the framework is is attached to.
Whether framework is used it operates via standard framework modules. Otherwise sends raw HTTP requests to url via PHPBrowser.
- Maintainer: tiger-seo, davert
- Stability: stable
- Contact: codecept@davert.mail.ua
- Contact: tiger.seo@gmail.com
- url optional - the url of api
This module requires PHPBrowser or any of Framework modules enabled.
modules:
enabled: [PhpBrowser, REST]
config:
PHPBrowser:
url: http://serviceapp/
REST:
url: 'http://serviceapp/api/v1/'
- headers - array of headers going to be sent.
- params - array of sent data
- response - last response (string)
Adds Bearer authentication via access token.
param$accessToken
s Digest authentication via username/password.
ram $username ram $password
Adds HTTP authentication via username/password.
param$usernameparam$password
Checks over the given HTTP header and (optionally) its value, asserting that are not there
param$nameparam$value
Checks that response code is not equal to provided value.
param$code
Checks whether last response do not contain text.
param$text
Opposite to seeResponseContainsJson
param array$json
Returns data from the current JSON response using specified path so that it can be used in next scenario steps
Example:
{% highlight php %}
grabDataFromJsonResponse('user.user_id'); $I->sendPUT('/user', array('id' => $user_id, 'name' => 'davert')); ?>{% endhighlight %}
-
param string$path -
available since version 1.1.2 @return string
@author tiger.seo@gmail.com
Returns the value of the specified header name
-
param$name -
param Boolean$first Whether to return the first value or all header values -
return string|array The first header value if$first is true, an array of values otherwise
Returns current response so that it can be used in next scenario steps.
Example:
{% highlight php %}
grabResponse(); $I->sendPUT('/user', array('id' => $user_id, 'name' => 'davert')); ?>{% endhighlight %}
@version 1.1 @return string
Sets HTTP header
param$nameparam$value
Checks over the given HTTP header and (optionally) its value, asserting that are there
param$nameparam$value
Checks that http response header is received only once. HTTP RFC2616 allows multiple response headers with the same name. You can check that you didn't accidentally sent the same header twice.
{% highlight php %}
seeHttpHeaderOnce('Cache-Control'); ?>>{% endhighlight %}
param$name
Checks response code equals to provided value.
param$code
Checks whether the last response contains text.
param$text
Checks whether the last JSON response contains provided array. The response is converted to array with json_decode($response, true) Thus, JSON is represented by associative array. This method matches that response array contains provided array.
Examples:
{% highlight php %}
seeResponseContainsJson(array('name' => 'john')); // response {user: john, profile: { email: john@gmail.com }} $I->seeResponseContainsJson(array('email' => 'john@gmail.com')); ?>{% endhighlight %}
This method recursively checks if one array can be found inside of another.
param array$json
Checks if response is exactly the same as provided.
param$response
Checks whether last response was valid JSON. This is done with json_last_error function.
Checks whether last response was valid XML. This is done with libxml_get_last_error function.
Sends DELETE request to given uri.
param$urlparam array$paramsparam array$files
Sends a GET request to given uri.
param$urlparam array$params
Sends a HEAD request to given uri.
param$urlparam array$params
Sends LINK request to given uri.
param$urlparam array$linkEntries (entry is array with keys "uri" and "link-param")
@link http://tools.ietf.org/html/rfc2068#section-19.6.2.4
@author samva.ua@gmail.com
Sends an OPTIONS request to given uri.
param$urlparam array$params
Sends PATCH request to given uri.
param$urlparam array$paramsparam array$files
Sends a POST request to given uri.
Parameters and files (as array of filenames) can be provided.
param$urlparam array$paramsparam array$files
Sends PUT request to given uri.
param$urlparam array$paramsparam array$files
Sends UNLINK request to given uri.
param$urlparam array$linkEntries (entry is array with keys "uri" and "link-param") @link http://tools.ietf.org/html/rfc2068#section-19.6.2.4 @author samva.ua@gmail.com