PHPackages                             tugrul/apigen - 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. tugrul/apigen

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

tugrul/apigen
=============

Generate REST API SDK libraries from annotated PHP interfaces. PSR-18 based, attribute-driven.

v1.0.3(4mo ago)03MITPHPPHP &gt;=8.1CI passing

Since Feb 25Pushed 4mo agoCompare

[ Source](https://github.com/tugrul/apigen)[ Packagist](https://packagist.org/packages/tugrul/apigen)[ RSS](/packages/tugrul-apigen/feed)WikiDiscussions master Synced today

READMEChangelog (4)Dependencies (12)Versions (5)Used By (0)

Tugrul ApiGen
=============

[](#tugrul-apigen)

**Generate REST API SDK clients from annotated PHP interfaces.**

Define your API surface as a PHP interface, decorate methods with attributes, run the generator — done. ApiGen handles URL building, parameter binding, body encoding, authentication, and response decoding. You bring the PSR-18 HTTP client of your choice.

```
// 1. Define
interface UserApi {
    #[GET('/users/{id}')]
    #[Returns('array')]
    public function getUser(#[Path] int $id): array;

    #[DELETE('/users/{id}')]
    public function deleteUser(#[Path] int $id): void;
}

// 2. Generate (once, at development time)
$gen = new StubGenerator(__DIR__ . '/Generated');
$gen->generate(UserApi::class);

// 3. Use
$client = ClientBuilder::create('https://api.example.com')
    ->withPsr18($httpClient, $psr17, $psr17, $psr17)
    ->withBearerToken('my-token')
    ->build();

$api  = new UserApiImpl($client);
$user = $api->getUser(42);
$api->deleteUser(42);
```

---

Requirements
------------

[](#requirements)

RequirementVersionPHP≥ 8.1psr/http-client^1.0psr/http-factory^1.0psr/http-message^1.1 || ^2.0Installation
------------

[](#installation)

```
composer require tugrul/apigen
```

Documentation
-------------

[](#documentation)

TopicDescription[Quick Start](docs/quick-start.md)Define → Generate → Use in 5 minutes[Attributes Reference](docs/attributes.md)Every attribute, target, and parameter[Authentication](docs/authentication.md)Built-in strategies, OAuth 2, custom auth[Code Generation](docs/generation.md)StubGenerator, naming strategies, PSR-4 paths[CLI Tool](docs/cli.md)`apigen generate`, `apigen list`, config files[Client Configuration](docs/client.md)ClientBuilder, middleware, custom decoders[ProxyRegistry](docs/proxy.md)Group multiple stubs under one object[Error Handling](docs/errors.md)ApiException, error table[Testing](docs/testing.md)Running tests, testing your own stubs[Architecture](docs/architecture.md)Package structure, request lifecycleKey Features
------------

[](#key-features)

- **Attribute-driven** — HTTP verbs, path/query/header/body binding, auth, encoding, and response types are all declared with native PHP 8 attributes. No XML, no YAML, no code to write beyond the interface.
- **PSR-18 transport** — bring your own HTTP client. Guzzle, Symfony HttpClient, Buzz, or any PSR-18 implementation.
- **Pluggable auth** — Bearer token, API key, Basic, HMAC, OAuth 2 client credentials, or your own `AuthStrategy`. Per-endpoint overrides with `#[UseAuth]`.
- **OAuth 2 token caching** — in-memory, PHP session, filesystem, or any PSR-16 store (Redis, Memcached, APCu). Auto-refresh with configurable leeway.
- **Five naming strategies** — control the generated class name and output namespace. Default, Suffix, Sub-namespace, Callable, and per-interface Map.
- **PSR-4 aware output paths** — reads `composer.json` to compute the correct subdirectory offset, avoiding double-nesting of namespace roots.
- **CLI tool** — `apigen generate` and `apigen list` commands with config file support.
- **Middleware** — chain pre/post request hooks for logging, retry, rate-limiting, and more.

At a Glance
-----------

[](#at-a-glance)

```
┌─────────────────────────────────────────────────────────────┐
│  Your PHP Interface  +  Attributes                          │
│        ↓  (apigen generate)                                 │
│  Generated Stub Class  (concrete, final, PSR-18 backed)     │
│        ↓                                                    │
│  ClientBuilder → DefaultSdkClient → PSR-18 HTTP Client      │
└─────────────────────────────────────────────────────────────┘

```

License
-------

[](#license)

MIT

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance78

Regular maintenance activity

Popularity3

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~2 days

Total

4

Last Release

121d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8203eaef0737a157a828b37dc85a63defa0d26e3f215135fe76cff6c67d2fa20?d=identicon)[tugrul](/maintainers/tugrul)

---

Top Contributors

[![tugrul](https://avatars.githubusercontent.com/u/163442?v=4)](https://github.com/tugrul "tugrul (7 commits)")

---

Tags

apisdkrestpsr-18generatorattributesphp8

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/tugrul-apigen/health.svg)

```
[![Health](https://phpackages.com/badges/tugrul-apigen/health.svg)](https://phpackages.com/packages/tugrul-apigen)
```

###  Alternatives

[guzzlehttp/psr7

PSR-7 message implementation that also provides common utility methods

8.0k1.1B4.0k](/packages/guzzlehttp-psr7)[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k15](/packages/tempest-framework)[telnyx/telnyx-php

Official Telnyx PHP SDK — APIs for Voice, SMS, MMS, WhatsApp, Fax, SIP Trunking, Wireless IoT, Call Control, and more. Build global communications on Telnyx's private carrier-grade network.

35789.4k2](/packages/telnyx-telnyx-php)[flow-php/flow

PHP ETL - Extract Transform Load - Data processing framework

85036.3k](/packages/flow-php-flow)[mollie/mollie-api-php

Mollie API client library for PHP. Mollie is a European Payment Service provider and offers international payment methods such as Mastercard, VISA, American Express and PayPal, and local payment methods such as iDEAL, Bancontact, SOFORT Banking, SEPA direct debit, Belfius Direct Net, KBC Payment Button and various gift cards such as Podiumcadeaukaart and fashioncheque.

60216.0M83](/packages/mollie-mollie-api-php)[getbrevo/brevo-php

Official Brevo provided RESTFul API V3 php library

1003.9M50](/packages/getbrevo-brevo-php)

PHPackages © 2026

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