Download the PHP package libinkk/api-starter without Composer
On this page you can find all versions of the php package libinkk/api-starter. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download libinkk/api-starter
More information about libinkk/api-starter
Files in libinkk/api-starter
Package api-starter
Short Description A production-ready API foundation for Laravel with standardized responses, filtering, sorting, validation, exception handling, and enterprise developer experience.
License MIT
Homepage https://www.libinkk.in
Informations about the package api-starter
libinkk/api-starter
A production-ready API foundation for Laravel applications with standardized responses, filtering, sorting, searching, pagination, sparse fields, relationship includes, validation, exception handling, request IDs, error codes, localization, versioning, and Artisan tooling.
It extends Laravel with opinionated best practices. It does not replace Laravel.
Table of contents
- Requirements
- Installation
- Quick start
- Response envelope
- Api facade helpers
- Exception handling
- Validation responses
- ApiQuery tutorial
- Filtering
- Searching
- Sorting
- Pagination
- Sparse fields
- Relationship includes
- Request ID
- Performance (response time)
- Error codes
- Localization
- API versioning
- Middleware
- Artisan commands
- Configuration reference
- End-to-end controller tutorial
- Testing
- Out of scope
- Changelog and license
Requirements
| Requirement | Version |
|---|---|
| PHP | 8.1+ (8.2, 8.3, 8.4 supported) |
| Laravel | 9, 10, 11, 12, 13 |
Installation
Publish config and language files:
Or publish manually:
Run the doctor to verify setup:
Register middleware (recommended)
In Laravel 11+ (bootstrap/app.php):
Or use aliases on specific routes:
Aliases registered by the package:
| Alias | Class |
|---|---|
api.performance |
MeasurePerformance |
api.request-id |
AssignRequestId |
api.locale |
SetLocale |
api.version |
SetApiVersion |
Quick start
Example request:
Response envelope
Success
Error
Paginated responses automatically fill meta (current page, last page, total, per page) and links (first, last, prev, next).
Optional timestamp can be enabled in config:
Api facade helpers
Method reference
| Method | HTTP status | Purpose |
|---|---|---|
success($data, $message, $status = 200, $meta, $links) |
200 (default) | Generic success |
created($data, $message, $meta) |
201 | Resource created |
updated($data, $message, $meta) |
200 | Resource updated |
deleted($message, $meta) |
200 | Resource deleted |
validation($errors, $message, $status = 422, $meta) |
422 | Validation failure |
error($message, $status, $errors, $meta, $errorCode) |
400 (default) | Generic error |
Laravel API Resources and paginators are supported as $data.
Exception handling
When enabled, API requests (Accept: application/json, or paths under /api/*) receive the package envelope automatically.
| Exception | Status | Error code |
|---|---|---|
ValidationException |
422 | VALIDATION_FAILED |
ModelNotFoundException |
404 | MODEL_NOT_FOUND |
AuthenticationException |
401 | UNAUTHENTICATED |
AuthorizationException |
403 | FORBIDDEN |
NotFoundHttpException |
404 | ROUTE_NOT_FOUND |
QueryException |
500 | QUERY_EXCEPTION |
| Other HTTP exceptions | varies | HTTP_EXCEPTION |
| Uncaught errors | 500 | SERVER_ERROR |
Custom API exceptions
Toggle with:
Set 'debug' => true (or API_STARTER_DEBUG=true) to expose detailed exception meta in development.
Validation responses
Form request / validator failures are converted to:
You can also return validation manually:
ApiQuery tutorial
ApiQuery is an allowlist-based query pipeline for Eloquent.
Filtering
Query examples
| Type | Request |
|---|---|
| Exact | ?status=active |
| Exact (IN) | ?status=active,pending |
| Partial | ?name=john |
| Boolean | ?is_active=true |
| Between | ?price=10,100 |
| Date range | ?created_at=2024-01-01,2024-12-31 |
| Date from/to | ?created_at_from=2024-01-01&created_at_to=2024-12-31 |
Nested filter keys (optional):
Only allowlisted filters are applied. Unknown query keys are ignored.
Searching
Default driver is SQL LIKE across the given columns (OR).
Custom search driver:
Sorting
| Request | Meaning |
|---|---|
?sort=name |
Ascending by name |
?sort=-created_at |
Descending by created_at |
?sort=name,-price |
Multiple sorts |
Disallowed sort fields are ignored.
Pagination
Also available:
Config defaults:
Helper utilities:
Sparse fields
Reduce payload size by selecting only allowlisted columns.
Notes:
- Only allowlisted fields are selected.
- Primary key is always included automatically when fields are requested.
- Disallowed fields (for example
password) are ignored.
Relationship includes
Eager-load allowlisted relations only (prevents arbitrary relation loading).
Request ID
Middleware api.request-id assigns a unique ID per request.
- Generates values like
REQ-8A7C9D2Xwhen missing - Keeps an incoming
X-Request-IDwhen provided - Adds the ID to the response header and response envelope
request_id
Useful for debugging, logging, support tickets, and monitoring.
Performance (response time)
Middleware api.performance measures how long the request took and exposes it like 40.12ms.
Output
Header
JSON body
Setup
Register api.performance as the outermost API middleware so timing covers the full request:
Config
Error codes
Stable codes make client-side branching easier.
Built-in codes:
VALIDATION_FAILEDMODEL_NOT_FOUNDUNAUTHENTICATEDFORBIDDENROUTE_NOT_FOUNDQUERY_EXCEPTIONHTTP_EXCEPTIONSERVER_ERRORUNSUPPORTED_API_VERSION
Add custom codes in config:
Prefer language files for localized custom codes:
Localization
Supported locales out of the box:
| Code | Language |
|---|---|
en |
English |
ta |
Tamil |
ml |
Malayalam |
hi |
Hindi |
de |
German |
it |
Italian |
es |
Spanish |
nl |
Dutch |
Set locale via (in order of priority):
- Header
X-Locale: de - Query
?lang=es Accept-Language
Success/error messages use:
Publish and customize:
Config:
API versioning
Resolve version from:
- Header
X-API-Version: v2 - Query
?api_version=v2 - Path
/api/v2/...
Unsupported versions return 400 with UNSUPPORTED_API_VERSION.
Example route groups:
Middleware
| Middleware | Alias | Responsibility |
|---|---|---|
MeasurePerformance |
api.performance |
Measure and expose response time (e.g. 40ms) |
AssignRequestId |
api.request-id |
Generate/propagate request ID |
SetLocale |
api.locale |
Set app locale from header/query/Accept-Language |
SetApiVersion |
api.version |
Resolve and validate API version |
Each feature can be disabled independently via features.* flags.
Artisan commands
Generated classes land under app/Filters, app/Sorts, and app/Transformers by default.
Use a custom filter with ApiQuery:
Configuration reference
File: config/api-starter.php
Feature flags
Nothing is mandatory. Disable what you do not need without editing package source.
Query parameters
End-to-end controller tutorial
1. Model
2. Controller
3. Routes
4. Try it
Check the response header and body for timing:
Testing
Package tests use Orchestra Testbench + PHPUnit.
In your app tests you can assert JSON structure:
Out of scope
This package intentionally does not include:
- Authentication / Authorization / RBAC
- Payment gateways
- File uploads
- Notifications
- Queue management
- Admin panels
- Business domain logic
Keep those in dedicated packages or your application.
Design principles
- Modular and optional
- Configurable (no source edits required)
- Consistent response envelopes
- Framework-friendly (PSR-12, SOLID, DI, interfaces)
- Compatible with Laravel API Resources, config cache, and route cache
Support
- Author: Libin K K
- Website: https://www.libinkk.in
- Email: [email protected]
- Mobile: +91 77087 82197
Changelog and license
See CHANGELOG.md for release notes.
Current package version: 1.0.0
Licensed under the MIT license.
All versions of api-starter with dependencies
illuminate/contracts Version ^9.0|^10.0|^11.0|^12.0|^13.0
illuminate/auth Version ^9.0|^10.0|^11.0|^12.0|^13.0
illuminate/database Version ^9.0|^10.0|^11.0|^12.0|^13.0
illuminate/http Version ^9.0|^10.0|^11.0|^12.0|^13.0
illuminate/pagination Version ^9.0|^10.0|^11.0|^12.0|^13.0
illuminate/routing Version ^9.0|^10.0|^11.0|^12.0|^13.0
illuminate/support Version ^9.0|^10.0|^11.0|^12.0|^13.0
illuminate/validation Version ^9.0|^10.0|^11.0|^12.0|^13.0