Would it be possible to use GraphQL to create virtual pages ?
I go through to the Kirby guide, the Remote class and some Graph QL tutorial but can’t figure out how to set the headers (for authentifications) and the query.
Would it look like like:
$request = Remote::get('https://the.requested.api', [
'header' => 'x-first-example: some-value \r\n x-second-example: another-value',
'query' => $json_query
]);
I think you probably have to send your request like this:
$url = 'https://the.requested.api';
$options = [
'headers' => [
'Authorization: Bearer ' . trim(option('your_api_key')), // depending on authentication method
'Content-Type: application/json'
],
'method' => 'POST',
'data' => $query
];
$response = Remote::request($url, $options);
1 Like
This definitely help, figure out that the client didnt give me the right credentials to output some datas, with the correct api key and Remote::request I was able to get my content!
Final result looks like that:
// Categories
$categories = '{
menu {
categories {
id
name
}
}
}';
$url = 'https://the.requested.api/graphql';
$options = [
'headers' => [
'Content-Type: application/json',
'x-apikey: xxxxXXXXxxxx',
'x-culture: fr-CA'
],
'method' => 'POST',
'data' => "{'query': '{$categories}'}",
];
$response = Remote::request($url, $options);
1 Like