Skip to content

Kirby 4.3.0

Remote::get()

Static method to send a GET request

Remote::get(string $url, array $params = [ ]): Kirby\Http\Remote

Parameters

Name Type Default
$url * string
$params array [ ]

Return type

Kirby\Http\Remote

Exceptions

Type Description
Exception when the curl request failed

Parent class

Kirby\Http\Remote

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 int|bool|string Remote::CA_INTERNAL TLS CA to use, see details
data array|string [] 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 free placekitten API, and write the content of the requested image to file:

<?php
$targetPage = page('home');
$response    = Remote::get('http://placekitten.com/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 ?>