PHPackages                             juststeveking/php-sdk - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. juststeveking/php-sdk

ActiveLibrary[HTTP &amp; Networking](/categories/http)

juststeveking/php-sdk
=====================

A framework for building SDKs in PHP.

3.0.0(2y ago)21872.0k↑25%152MITPHPPHP ^8.3CI passing

Since Oct 29Pushed 7mo ago7 watchersCompare

[ Source](https://github.com/JustSteveKing/php-sdk)[ Packagist](https://packagist.org/packages/juststeveking/php-sdk)[ GitHub Sponsors](https://github.com/sponsors/JustSteveKing)[ RSS](/packages/juststeveking-php-sdk/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (9)Dependencies (18)Versions (11)Used By (2)

PHP SDK
=======

[](#php-sdk)

[![Latest Version](https://camo.githubusercontent.com/9f6d45b669bf6fdc54fbbc8bfd4ddfe43922cfa2fea282d15b7913b06cbba605/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a75737473746576656b696e672f7068702d73646b2e7376673f7374796c653d666c61742d737175617265266c6162656c3d72656c65617365)](https://packagist.org/packages/juststeveking/php-sdk)[![PHP Version](https://camo.githubusercontent.com/49de24ab087ab125228c46b940bdb2adef5a91dd4dff801d36ac1eafa47cd293/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6a75737473746576656b696e672f7068702d73646b2e7376673f7374796c653d666c61742d737175617265)](https://php.net)[![tests](https://github.com/JustSteveKing/php-sdk/workflows/tests/badge.svg)](https://github.com/JustSteveKing/php-sdk/workflows/tests/badge.svg)[![Total Downloads](https://camo.githubusercontent.com/4d99f036a2ad7844979a574197982ddbd4eb231b0bd799d1fb3b7927f77349cd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a75737473746576656b696e672f7068702d73646b2e7376673f7374796c653d666c61742d73717561726526636f6c6f72423d6d656469756d76696f6c6574726564)](https://packagist.org/packages/juststeveking/php-sdk)

A framework for building SDKs in PHP.

Installation
------------

[](#installation)

```
composer require juststeveking/php-sdk
```

Purpose
-------

[](#purpose)

The purpose of this package is to provide a consistent and interoperable way to build PHP SDKs to work with 3rd party APis.

Usage
-----

[](#usage)

To get started with this library, you need to start by extending the `Client` class. Let's walk through building an SDK.

### Create your SDK class

[](#create-your-sdk-class)

```
use JustSteveKing\Sdk\Client;

final class YourSDK extends Client
{
    //
}
```

Once this is in place, you can start adding your resources to the class. Let's add a `projects` method for a projects resource.

```
use JustSteveKing\Sdk\Client;
use JustSteveKing\Sdk\Tests\Stubs\Resources\ProjectResource;

final class YourSDK extends Client
{
    public function projects()
    {
        return new ProjectResource(
            client: $this,
        );
    }
}
```

We return a new instance of our resource classes, passing through your SDK as a `client`. This is so that each resource is able to talk through the client to send requests.

Now, let's look at how to structure a resource.

```
final class ProjectResource
{
    //
}
```

To save time, there are a collection of traits that you can use on your resources.

- `CanAccessClient` - which will add the default constructor required for a resource.
- `CanCreateDataObjects` - which will allow you to create DataObjects from API responses.
- `CanCreateRequests` - which will allow you to create HTTP requests and payloads using PSR-17 Factories.

Let's look at an example of a full resource class.

```
use Exception;
use JustSteveKing\Sdk\Concerns\Resources;
use JustSteveKing\Tools\Http\Enums\Method;
use Ramsey\Collection\Collection;
use Throwable;

final class ProjectResource
{
    use Resources\CanAccessClient;
    use Resources\CanCreateDataObjects;
    use Resources\CanCreateRequests;

    public function all(): Collection
    {
        $request = $this->request(
            method: Method::GET,
            uri: '/projects',
        );

        try {
            $response = $this->client->send(
                request: $request,
            );
        } catch (Throwable $exception) {
            throw new Exception(
                message: 'Failed to list test.',
                code: $exception->getCode(),
                previous: $exception,
            );
        }

        return (new Collection(
            collectionType: Project::class,
            data: array_map(
                callback: static fn(array $data): Project => Project::make(
                    data: $data,
                ),
                array: (array) json_decode(
                    json: $response->getBody()->getContents(),
                    associative: true,
                    flags: JSON_THROW_ON_ERROR,
                ),
            ),
        ));
    }
}
```

We start by creating a request, and then try to get a response by sending it through the client.

Once we have a response, we create a `Collection` thanks to a package by Ben Ramsey. We pass through the type of each item we expect it to be, then the data as an array. To create the data we map over the response content and statically create a new Data Object.

This allows us to keep our code clean, concise, and testable.

Testing
-------

[](#testing)

To run the test:

```
composer run test
```

Static analysis
---------------

[](#static-analysis)

To run the static analysis checks:

```
composer run stan
```

Code Style
----------

[](#code-style)

To run the code style fixer:

```
composer run pint
```

Refactoring
-----------

[](#refactoring)

To run the rector code refactoring:

```
composer run refactor
```

Special Thanks
--------------

[](#special-thanks)

Without the following packages and people, this framework would have been a lot harder to build.

- [The PHP League - Object Mapper](https://github.com/thephpleague/object-mapper)
- [Ben Ramsey - Collection](https://github.com/ramsey/collection)
- [Larry Garfield - Serde](https://github.com/crell/serde)

Credits
-------

[](#credits)

- [Steve McDougall](https://github.com/JustSteveKing)
- [All Contributors](../../contributors)

LICENSE
-------

[](#license)

The MIT License (MIT). Please see [License File](./LICENSE) for more information.

###  Health Score

51

—

FairBetter than 96% of packages

Maintenance44

Moderate activity, may be stable

Popularity47

Moderate usage in the ecosystem

Community23

Small or concentrated contributor base

Maturity75

Established project with proven stability

 Bus Factor1

Top contributor holds 84.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~129 days

Recently: every ~235 days

Total

10

Last Release

867d ago

Major Versions

v1.1.3 → v2.0.02021-06-03

v2.2.0 → 3.0.02024-01-02

PHP version history (3 changes)v1.1.0PHP ^7.4|^8.0

v2.0.1PHP ^8.0|^8.1

3.0.0PHP ^8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/a87fe82b349821ebd49cf57d65c4cd3e33ae0833222a8438d90fe8921ca899ea?d=identicon)[JustSteveKing](/maintainers/JustSteveKing)

---

Top Contributors

[![JustSteveKing](https://avatars.githubusercontent.com/u/6368379?v=4)](https://github.com/JustSteveKing "JustSteveKing (79 commits)")[![cpats007](https://avatars.githubusercontent.com/u/5278964?v=4)](https://github.com/cpats007 "cpats007 (6 commits)")[![chapterjason](https://avatars.githubusercontent.com/u/1337562?v=4)](https://github.com/chapterjason "chapterjason (4 commits)")[![Jxckaroo](https://avatars.githubusercontent.com/u/24681027?v=4)](https://github.com/Jxckaroo "Jxckaroo (3 commits)")[![johncongdon](https://avatars.githubusercontent.com/u/67472?v=4)](https://github.com/johncongdon "johncongdon (1 commits)")

---

Tags

phpsdkpsr-18sdk-framework

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Rector

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/juststeveking-php-sdk/health.svg)

```
[![Health](https://phpackages.com/badges/juststeveking-php-sdk/health.svg)](https://phpackages.com/packages/juststeveking-php-sdk)
```

###  Alternatives

[openai-php/client

OpenAI PHP is a supercharged PHP API client that allows you to interact with the Open AI API

5.8k22.6M232](/packages/openai-php-client)[phpro/http-tools

HTTP tools for developing more consistent HTTP implementations.

28137.8k](/packages/phpro-http-tools)[mozex/anthropic-php

Anthropic PHP is a supercharged community-maintained PHP API client that allows you to interact with Anthropic API.

46365.1k13](/packages/mozex-anthropic-php)[getbrevo/brevo-php

Official Brevo provided RESTFul API V3 php library

963.1M35](/packages/getbrevo-brevo-php)[open-telemetry/sdk

SDK for OpenTelemetry PHP.

2322.9M248](/packages/open-telemetry-sdk)[php-soap/psr18-transport

PSR-18 HTTP Client transport for SOAP

183.4M20](/packages/php-soap-psr18-transport)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
