Search by

rasket / rasket-php

123sam123

The Rasket PHP client. Typed against the API's own OpenAPI document; retries only what is safe to repeat.

v0.1.0 2026-12-01 06:43 UTC

This package is auto-updated.

Last update: 2026-12-01 07:17:52 UTC


README

Rasket is one platform for transactional email, marketing email, SMS, sign-up forms, automations and free business email with Rasket Mail.

rasket/rasket-php is its official PHP client: transactional sends, domains, contacts, segments, broadcasts, webhooks and suppressions. Generated from the API's own OpenAPI document, PHP 8.2+, with no dependencies beyond ext-curl and ext-json.

composer require rasket/rasket-php
<?php

require __DIR__ . '/vendor/autoload.php';

$rasket = new Rasket\Client(getenv('RASKET_API_KEY'), ['user_agent' => 'acme-billing/1.0']);

$sent = $rasket->emails->send([
    'from' => 'Acme <billing@acme.example>',
    'to' => ['ronald.williams@example.com'],
    'subject' => 'Your receipt',
    'html' => '<p>Thanks.</p>',
], ['idempotency_key' => 'receipt-1042']);

echo $sent->body['id'];

Docs: rasket.com/docs/sdk/php.

What every call returns

A Rasket\Response, or an exception:

$result = $rasket->emails->get($emailId);

$result->body;               // the decoded JSON body, an array
$result->rateLimit;          // RateLimit { limit: 10, remaining: 9, resetSeconds: 1 }
$result->requestId;          // the x-request-id to quote when asking about a request
$result->idempotentReplayed; // true when this answers an earlier request with the same key

Every body and response shape is a PHPStan / Psalm array-shape type in Rasket\Types, so a static analyser checks the keys you send.

The surface

$rasket->emails, batch, domains, contacts, segments, broadcasts, webhooks and suppressions, with the Node client's method names: $rasket->webhooks->rotateSecret($id), $rasket->emails->receiving->attachments->list($emailId). Path parameters come first, then the body or query array, then an options array (idempotency_key where the route takes one, timeout). A null in a body is sent as null.

Every list method that pages has an All twin, a generator that walks every page:

foreach ($rasket->domains->listAll() as $domain) {
    echo $domain['name'], "\n";
}

Errors

use Rasket\ErrorName;
use Rasket\Exception\ApiException;
use Rasket\Exception\ConnectionException;

try {
    $rasket->emails->send($message);
} catch (ApiException $error) {
    if ($error->name === ErrorName::VALIDATION_ERROR) {
        // $error->errors: list<ValidationIssue> with ->path and ->message
    } elseif ($error->name === ErrorName::RATE_LIMIT_EXCEEDED) {
        // $error->rateLimit?->retryAfterSeconds
    }
} catch (ConnectionException $error) {
    // $error->reason: 'network' or 'timeout'; no answer arrived
}

Retries

Only what is safe to repeat is retried: a GET, or a send carrying an idempotency key. The client retries a network error, a 429 rate_limit_exceeded (never a quota), a 5xx other than 501, and 409 concurrent_idempotent_requests; it obeys retry-after up to the longest wait and otherwise backs off with jitter. Options: timeout (seconds, default 30) and retry (['attempts' => 3, 'min_delay' => 0.5, 'max_delay' => 8]).

Webhooks

use Rasket\Exception\WebhookVerificationException;
use Rasket\Webhooks;

$raw = file_get_contents('php://input'); // the raw body, never a decoded copy
try {
    $event = Webhooks::verify($raw, getallheaders(), getenv('RASKET_WEBHOOK_SECRET'));
} catch (WebhookVerificationException $error) {
    http_response_code(400);
    exit;
}

Documentation: https://www.rasket.com/docs/sdk/php. MIT licensed.