protected function ApiTestBase::request in Lightning API 8
Same name and namespace in other branches
- 8.2 modules/api_test/tests/src/Functional/ApiTestBase.php \Drupal\Tests\api_test\Functional\ApiTestBase::request()
Makes a request to the API using an optional OAuth token.
Parameters
string $endpoint: Path to the API endpoint.
string $method: The RESTful verb.
string $token: A valid OAuth token to send as an Authorization header with the request.
array $data: Additional json data to send with the request.
Return value
\Psr\Http\Message\ResponseInterface The response from the request.
3 calls to ApiTestBase::request()
- ApiTest::testAllowed in modules/
api_test/ tests/ src/ Functional/ ApiTest.php - Tests Getting data as anon and authenticated user.
- ApiTest::testNotAllowed in modules/
api_test/ tests/ src/ Functional/ ApiTest.php - Tests that authenticated and anonymous requests cannot get unauthorized data.
- EntityCrudTest::testEntities in modules/
api_test/ tests/ src/ Functional/ EntityCrudTest.php - Tests create, read, and update of content entities via the API.
File
- modules/
api_test/ tests/ src/ Functional/ ApiTestBase.php, line 92
Class
Namespace
Drupal\Tests\api_test\FunctionalCode
protected function request($endpoint, $method = 'get', $token = NULL, $data = NULL) {
$client = $this->container
->get('http_client');
$options = NULL;
if ($token) {
$options = [
'headers' => [
'Authorization' => 'Bearer ' . $token,
'Content-Type' => 'application/vnd.api+json',
],
];
}
if ($data) {
$options['json'] = $data;
}
$url = $this
->buildUrl($endpoint);
return $client
->{$method}($url, $options);
}