How to use your API

Supply your API's environment and factory through the application's composition code. In Laravel, inject MakeApiFactory into the class that builds API clients:

namespace ExampleSdk;

use ExampleSdk\Environments\LiveEnvironment;
use WrkFlow\ApiSdkBuilder\Actions\MakeApiFactory;

final class ExampleApiFactory
{
    public function __construct(private readonly MakeApiFactory $makeApiFactory)
    {
    }

    public function create(string $apiKey): ExampleApi
    {
        return new ExampleApi(
            environment: new LiveEnvironment($apiKey),
            factory: $this->makeApiFactory->execute(),
        );
    }
}

Outside Laravel, supply a compatible SDKContainerFactoryContract to MakeApiFactory, or construct ApiFactory with all its required PSR services. The factory needs request, client, stream, container, and response implementations.

Call $api->units()->get('42') to receive UnitResponse. Catch SDK exceptions at the application's external API boundary. See Responses for status handling and Testing for network-free checks.

Edit this page on GitHub Updated at Thu, Nov 5, 2026