Remote::get()
Static method to send a GET request
Remote::get(string $url, array $params = [ ]): Kirby\Http\Remote
Parameters
| Name | Type | Default |
|---|---|---|
| $urlrequired | string |
no default value |
| $params | array |
[ ]
|
Return type
Exceptions
| Type | Description |
|---|---|
Exception |
when the curl request failed |
Parent class
Remote::get() is a shortcut for Remote::request() with method GET.
Params array
Default parameters:
| Key | Type | Default | Description |
|---|---|---|---|
| agent | string |
null |
The user agent string to be sent with the HTTP request |
| basicAuth | string |
null |
User name and password to use for the Authorization header (formatted as USERNAME:PASSWORD) |
| body | bool |
true |
When true returns transfer as string instead of outputting it directly |
| ca |
intorboolorstring
|
Remote::CA_INTERNAL |
TLS CA to use, see details |
| data |
arrayorstring
|
[] |
The data to be sent with the request |
| encoding | string |
utf-8 |
Accepted values: null, '', identity, gzip, br
|
| file | string |
null |
Path to file to be uploaded |
| headers | array |
[] |
Array of headers to be sent with the request |
| method | string |
GET |
HTTP method (GET, POST, PUT, PATCH, DELETE, HEAD) |
| progress | callback |
null |
A callback which accepts 5 parameters, if you want to handle upload/download progress |
| test | bool |
false |
When set to true, the cURL request is not initiated, and the Remote object returned |
| timeout | int |
10 |
Request/connect timeout |
Examples
In this example, we make a GET request to the picsum API, and write the content of the requested image to file:
<?php
$targetPage = page('home');
$response = Remote::get('https://picsum.photos/200/300');
if ($response->code() === 200) {
F::write($targetPage->root() . '/kitten.jpg', $response->content());
}
<?php
$response = Remote::get('https://rickandmortyapi.com/api/character/108');
if ($response->code() === 200): ?>
<?php $character = $response->json(); ?>
<dl>
<dt>Name</dt>
<dd><?= $character['name'] ?></dd>
<dt>Status</dt>
<dd><?= $character['status'] ?></dd>
<dt>Gender</dt>
<dd><?= $character['gender'] ?></dd>
<dt>Type</dt>
<dd><?= $character['type'] ?></dd>
</dl>
<?php endif ?>