PHPackages                             stefna/api-client-runtime - 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. [API Development](/categories/api)
4. /
5. stefna/api-client-runtime

ActiveLibrary[API Development](/categories/api)

stefna/api-client-runtime
=========================

Base package for api clients

1.9.0(8mo ago)06MITPHPPHP ^8.0

Since Jan 16Pushed 8mo ago3 watchersCompare

[ Source](https://github.com/stefna/api-client-runtime)[ Packagist](https://packagist.org/packages/stefna/api-client-runtime)[ RSS](/packages/stefna-api-client-runtime/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (9)Versions (12)Used By (0)

Stefna Api Client Runtime
=========================

[](#stefna-api-client-runtime)

[![Latest Version on Packagist](https://camo.githubusercontent.com/8d1a7ac0cb529e0b82483dab5a1555421d305714cb784903e75fe4d4c71eabf3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f737465666e612f64692e737667)](https://packagist.org/packages/stefna/di)[![Software License](https://camo.githubusercontent.com/3c590a70fdf7030d2b863f4580b3f8fa66150ec36a8c7427e2193494b5aa7a23/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f737465666e612f64692e737667)](LICENSE)

Base classes to make it easier to create apis.

Used by Stefna OpenApi Generator among others.

Usage
-----

[](#usage)

To create an api-client you will need 2 classes

First is a `ServerConfiguration` class that contains information about the api you want to connect to

Example:

```
class ServerConfiguration extends AbstractServerConfiguration
{
	/** @var string[] */
	protected array $serverUris = [
		'production' => 'https://api.example.com',
		'staging' => 'https://staging.api.example.com',
	];
	protected string $selectedBaseUri = 'production';
	protected SecurityScheme $securityScheme;
	protected SecurityValue $securityValue;

	public function __construct(SecurityValue $token)
	{
		$this->securityScheme = new ApiKeySecurityScheme('access-token', 'X-Api-Token', 'header');
		$this->securityValue = $token;
	}

	public function getBaseUri(): string
	{
		return $this->serverUris[$this->selectedBaseUri];
	}

	public function selectServer(string $name): void
	{
		$this->selectedBaseUri = $name;
	}

	public function getSecurityScheme(string $ref): ?SecurityScheme
	{
		return $this->securityScheme;
	}

	public function getSecurityValue(string $ref): ?SecurityValue
	{
		return $this->securityValue;
	}
}
```

And the second one is the actual api-client

```
final class Service extends AbstractService
{
	public function getNews(string $lang): array
	{
		$response = $this->doRequest(new \Stefna\ApiClientRuntime\Endpoint\Endpoint(
			'GET',
			'/news/' . $lang,
			security: ['access-token'],
		));

		return $this->parseJsonResponse($response);
	}

	public function sendNotification(string $to, string $from, string $text)
	{
		$response = $this->doRequest(new \Stefna\ApiClientRuntime\Endpoint\Endpoint(
			'POST',
			'/notification',
			new \Stefna\ApiClientRuntime\RequestBody\JsonData([
				'to' => $to,
				'from' => $from,
				'text' => $text,
			]),
			security: ['access-token'],
		));

		return $this->parseJsonResponse($response);
	}

	public function sendPostData(array $postData): bool
	{
		$response = $this->doRequest(new \Stefna\ApiClientRuntime\Endpoint\Endpoint(
			'POST',
			'/post-endpoint',
			new \Stefna\ApiClientRuntime\RequestBody\PostData($postData)
			security: ['access-token'],
		));

		return $this->parseJsonResponse($response);
	}

	public static function createWithToken(string $token): self
	{
		return static::create(new ServerConfiguration(AuthSecurityValue::raw($token)));
	}
}
```

Consuming api service
---------------------

[](#consuming-api-service)

When consuming the api-client you can create it with 2 different methods

### Simple creation

[](#simple-creation)

The simple way is to use the static `create` method.

But for that method to work you need to have `nyholm/psr7` and `kriswallsmith/buzz` installed since that's the default psr implementations we use

```
$service = Service::create(new ServerConfiguration(...));

// use service
```

### Create with custom psr implementations

[](#create-with-custom-psr-implementations)

If you want you can provide your own Client and Request implementations

```
$service = new Service(
	new ServerConfiguration(...),
	new GuzzleHttp\Client(),
	new GuzzleHttp\Psr7\HttpFactory(),
);
```

License
-------

[](#license)

View the [LICENSE](LICENSE) file attach to this project.

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance62

Regular maintenance activity

Popularity4

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 96.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 ~76 days

Recently: every ~84 days

Total

9

Last Release

242d ago

### Community

Maintainers

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

---

Top Contributors

[![sunkan](https://avatars.githubusercontent.com/u/568492?v=4)](https://github.com/sunkan "sunkan (31 commits)")[![bix0r](https://avatars.githubusercontent.com/u/2131100?v=4)](https://github.com/bix0r "bix0r (1 commits)")

###  Code Quality

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/stefna-api-client-runtime/health.svg)

```
[![Health](https://phpackages.com/badges/stefna-api-client-runtime/health.svg)](https://phpackages.com/packages/stefna-api-client-runtime)
```

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[theodo-group/llphant

LLPhant is a library to help you build Generative AI applications.

1.5k311.5k5](/packages/theodo-group-llphant)[swisnl/json-api-client

A PHP package for mapping remote JSON:API resources to Eloquent like models and collections.

211473.2k12](/packages/swisnl-json-api-client)[wordpress/php-ai-client

A provider agnostic PHP AI client SDK to communicate with any generative AI models of various capabilities using a uniform API.

26236.6k14](/packages/wordpress-php-ai-client)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)[phpro/http-tools

HTTP tools for developing more consistent HTTP implementations.

28137.8k](/packages/phpro-http-tools)

PHPackages © 2026

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