Search by

royfee / basesdk

royfee

A modern PHP SDK foundation package for building API clients with ease.

Package info

github.com/royfee/basesdk

pkg:composer/royfee/basesdk

Statistics

Installs: 6

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

1.0.1 2026-09-15 14:24 UTC

This package is auto-updated.

Last update: 2026-09-15 14:25:49 UTC


README

A modern PHP SDK foundation package for building API clients with ease.

Based on hanson/foundation-sdk, redesigned with PSR standards and improved architecture.

Features

Feature Description
PSR-3 Logging Standard logger interface, Monolog optional
PSR-16 Cache Built-in file cache, or bring your own
HTTP Client Guzzle wrapper with GET/POST/PUT/PATCH/DELETE/Upload
Middleware Interface-based pipeline with auth & retry built-in
Response Wrapper Auto JSON decode, status helpers
Token Management Auto-cached access token with refresh
Dot-notation Config Access nested config with log.file syntax

Requirements

  • PHP >= 7.4
  • ext-curl
  • ext-json

Installation

composer require royfee/basesdk

For file-based logging, install Monolog:

composer require monolog/monolog

Quick Start

use Royfee\BaseSdk\Application;
use Royfee\BaseSdk\Api\AbstractApi;

// 1. Create the application
$app = new Application([
    'debug' => true,
    'log'   => [
        'file'  => __DIR__ . '/logs/sdk.log',
        'level' => \Monolog\Logger::DEBUG,
    ],
]);

// 2. Define your API class
class MyApi extends AbstractApi
{
    protected function getBaseUrl(): string
    {
        return 'https://api.example.com/v1';
    }

    protected function getDefaultHeaders(): array
    {
        return [
            'Authorization' => 'Bearer ' . $this->app->getConfig('token'),
            'Content-Type'  => 'application/json',
        ];
    }

    public function getUsers(): array
    {
        $response = $this->getHttp()->postJson(
            $this->getBaseUrl() . '/users',
            [],
            $this->getDefaultHeaders()
        );

        return $response->toArray();
    }
}

// 3. Use it
$api = new MyApi($app);
$users = $api->getUsers();

Documentation

See the doc/ directory for detailed documentation:

Examples

Testing

composer test

Static Analysis

composer analyse

License

MIT License. See LICENSE for details.