Download the PHP package tetes-de-pioche/laravel-modular-api without Composer
On this page you can find all versions of the php package tetes-de-pioche/laravel-modular-api. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download tetes-de-pioche/laravel-modular-api
More information about tetes-de-pioche/laravel-modular-api
Files in tetes-de-pioche/laravel-modular-api
Package laravel-modular-api
Short Description A Laravel package for creating JSON:API-compliant REST APIs, with support for versioning and multiple sub-APIs, organized into standalone, modular services.
License LicenseRef-DBAD
Homepage https://github.com/tetes-de-pioche/laravel-modular-api
Informations about the package laravel-modular-api
Laravel Modular API
Key Features:
- JSON:API Compliance: Generate API responses that fully comply with the JSON:API specification, ensuring data consistency and interoperability (built on Laravel's native JSON:API resources)
- Autonomous Services: Structure your business logic into independent services, facilitating code reuse and clear separation of concerns.
- API Versioning: Easily version your API to manage changes and ensure backward compatibility.
- Sub-APIs: Create multiple sub-APIs (e.g.,
public,protected,private, ...) to handle different access levels and use cases. - Localization: Serve multi-language content by processing a request header that automatically sets the locale for the entire request.
- Obfuscated IDs: Expose short, non-sequential identifiers instead of raw database keys, decoded transparently on the way in.
- JSON:API pagination: Paginate any Eloquent query with the
page[number]/page[size]members, links included. - Negotiated errors: Serve spec compliant JSON:API error objects to clients that ask for them, without breaking clients built against the Laravel error shape.
- Flexibility and Extensibility: The package is designed to be extensible, allowing you to adapt services to specific needs while following best development practices.
Version support
- PHP:
8.3,8.4 - Laravel:
13.0
Installation
You can install the package via composer:
If you want to use obfuscated ids (short, non-sequential identifiers derived from your primary keys) for your resources, you can install the required package via composer:
If you want to customize the configuration, you can publish the config file:
This is the contents of the published config file:
Getting started
Services directory structure:
Querying
Two builder macros implement the JSON:API request contract on any Eloquent query:
jsonApiPaginate() takes an optional default and maximum page size, to raise the cap on a bounded-cardinality
resource that may be fetched in a single page:
jsonApiFind() decodes the identifier when the obfuscated ids feature is enabled, and raises a
ResourceNotFoundException when nothing matches.
Both are registered on Illuminate\Database\Eloquent\Builder, so query builder packages forwarding unknown calls to
their underlying builder — spatie/laravel-query-builder among them — pick them up with no extra wiring.
Obfuscated IDs
The feature is optional: install sqids/sqids to use it. Enabling it without the package raises a
FeatureInvalidException.
When the feature is enabled, ApiResource exposes Sqids identifiers instead of raw primary keys,
and BaseRequest decodes them back before validation runs. Sqids has no salt of its own: the package derives a
project-specific alphabet from a deterministic, key-seeded shuffle, so two applications with different keys never
produce the same identifier for the same row.
Opt a resource out with:
Encoding is handled by Features\ObfuscatedIdEncoder, bound as a singleton. Bind your own implementation to change the
strategy:
Errors
Error responses are negotiated on the Accept header, so adopting the package on an existing API does not break its
consumers.
A client sending Accept: application/vnd.api+json gets JSON:API error objects, with the matching Content-Type:
Any other client keeps the Laravel shape:
source follows the request document assembled by BaseRequest: a validation key matching a route parameter is
reported as source.parameter, every other key as a /data/attributes pointer with dots as nested segments.
The package renders framework exceptions (ValidationException, NotFoundHttpException) as API responses only for
API requests, so web endpoints keep the default Laravel behaviour. Its own BaseException is always rendered as an
API response.
License
The DBAD License (DBAD). Please see License File for more information.