Download the PHP package silencenjoyer/api-sdk without Composer
On this page you can find all versions of the php package silencenjoyer/api-sdk. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download silencenjoyer/api-sdk
More information about silencenjoyer/api-sdk
Files in silencenjoyer/api-sdk
Package api-sdk
Short Description A lightweight PHP SDK for creating API integrations.
License MIT
Informations about the package api-sdk
🛠️ API SDK
A lightweight PHP framework for building typed HTTP API integrations.
Requirements
- PHP 7.4 or 8.x
- PSR-18 HTTP client
- PSR-17 HTTP factories (request factory + stream factory)
Installation
The package includes php-http/discovery and will auto-discover PSR-18/PSR-17 implementations. Install any compatible package alongside:
Overview
The SDK is organized around two layers:
- Layer 1 — end users: consume a ready-made API client (
NbuApi,StripeApi, etc.) - Layer 2 — integration developers: build those clients by extending
AbstractApi
Layer 1: Using an API client
Zero-config instantiation
If php-http/discovery is installed alongside compatible PSR-18/PSR-17 packages, the client discovers them automatically:
Explicit dependencies:
Advanced builder
For middleware or parser customization, obtain the builder first:
Authentication
Attach an auth strategy to a built instance. The call is immutable and returns a new instance:
Implement AuthInterface to create custom strategies (API key header, HMAC signature, etc.).
Executing commands
Two styles are available:
Working with the response
Layer 2: Building an API client
Minimal implementation
Providing default builder configuration
Override getBuilder() to apply defaults that are always needed for this API. The signature must match the parent:
AbstractApi::build() calls static::getBuilder(), so defaults are applied automatically for both NbuApi::build() and NbuApi::getBuilder().
Custom constructor parameters
If your API requires extra constructor arguments (e.g., an environment-specific base URL), add a named factory method that uses withFactory():
Implementing commands
Extend AbstractCommand and declare the HTTP semantics:
Override getBodyParams(), getHeaders(), getRequestContentType(), or getAnswerContentType() as needed.
For private commands, isPublic() must return false. The authentication strategy attached via withAuthentication() will sign the request automatically.
Per-command middleware
Attach middleware to a specific command class only:
Custom middleware
Implement MiddlewareInterface:
Custom parsers and serializers
Register additional format support on the builder:
Serializer resolution
When a command has body params, the SDK selects a serializer using this priority chain:
getRequestContentType()— explicit override on the command.- The
Content-Typeheader already present on the request — set it viagetHeaders()to let the SDK pick the serializer automatically. - If neither provides a recognized content type,
UnableToResolveSerializerExceptionis thrown.
The recognized content types are controlled by withFormats() on the builder.
Parser resolution
After a response is received, the SDK selects a parser using this priority chain:
getAnswerContentType()— explicit override on the command; bypasses all automatic detection.- The
Content-Typeheader on the response — matched against the content types registered viawithFormats(). - Assumes — when the header is absent or unrecognized, the body is inspected by registered assume strategies.
JsonAssumeis active by default. - If none of the above resolves,
UnableToResolveParserExceptionis thrown.
Content-type inference
When a response carries no Content-Type header, the SDK uses registered "assumes" to infer the format from the body. JSON is assumed by default. Register additional strategies:
Built-in components
| Component | Description |
|---|---|
LoggerMiddleware |
Logs request and response bodies via PSR-3 |
RepeatableMiddleware |
Retries requests on 5xx by default; configurable condition and retry count |
RateLimiterMiddleware |
Throttles outgoing requests via silencenjoyer/rate-limiter; blocks until the rate window allows |
ThrowOnErrorStatusMiddleware |
Throws ClientHttpException on 4xx and ServerHttpException on 5xx; opt-in |
Bearer |
Adds Authorization: Bearer <token> header |
JsonParser |
Parses JSON responses |
JsonSerializer |
Serializes request bodies as JSON |
UrlEncodedSerializer |
Serializes request bodies as application/x-www-form-urlencoded |
License
MIT
All versions of api-sdk with dependencies
psr/http-message Version ^1.1|^2.0
psr/http-client Version ^1.0.0
psr/http-factory Version ^1.0.0
psr/log Version ~1.1.0
silencenjoyer/rate-limiter Version ^3.0.0
php-http/discovery Version ^1.0
ext-json Version *