private function ApiTest::request in Lightning API 8.3
Same name and namespace in other branches
- 8.4 tests/src/Functional/ApiTest.php \Drupal\Tests\lightning_api\Functional\ApiTest::request()
Makes a request to the API using an optional OAuth token.
Parameters
string $endpoint: Path to the API endpoint.
string $method: (optional) The RESTful verb. Defaults to 'get'.
string $token: (optional) A valid OAuth token to send as an Authorization header with the request.
array $data: (optoinal) Additional JSON data to send with the request.
Return value
\Psr\Http\Message\ResponseInterface The response from the request.
3 calls to ApiTest::request()
- ApiTest::testAllowed in tests/
src/ Functional/ ApiTest.php - Tests Getting data as anon and authenticated user.
- ApiTest::testEntities in tests/
src/ Functional/ ApiTest.php - Tests create, read, and update of content entities via the API.
- ApiTest::testForbidden in tests/
src/ Functional/ ApiTest.php - Tests that authenticated and anonymous users cannot get unauthorized data.
File
- tests/
src/ Functional/ ApiTest.php, line 304
Class
- ApiTest
- Tests OAuth and JSON:API authentication and interactions with entities.
Namespace
Drupal\Tests\lightning_api\FunctionalCode
private function request($endpoint, $method = 'get', $token = NULL, array $data = NULL) {
$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 $this->container
->get('http_client')
->{$method}($url, $options);
}