Download the PHP package yoosuf/laravel-api without Composer

On this page you can find all versions of the php package yoosuf/laravel-api. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-api

yoosuf/laravel-api

Production-ready Laravel API toolkit: consistent response envelopes, structured error formats, OpenAPI 3 generation, request correlation, API versioning, exception rendering, paginator adapters, ETag helpers, security headers, and a health check endpoint — all in one package.

Features

Response building

Middleware

Exception handling

OpenAPI generation

Health check

Testing utilities


Installation

Path repository (monorepo / local)

Add the path repository in root composer.json:

Require and publish:

Packagist (once published)


Quick start

1. Register recommended middleware

In app/Http/Kernel.php, add to the api middleware group:

Or use the named aliases registered by the package:

2. Auto-register exception rendering (optional)

In .env:

Or register manually in AppServiceProvider::boot():

This converts AuthenticationException, ValidationException, ModelNotFoundException, and HttpException into consistent JSON API responses automatically.

3. Use HasApiResponses in controllers

4. Or use the Facade / helpers directly


Response formats

Envelope format (default)

Success:

Error:

Structured format

Set LARAVEL_API_ERROR_FORMAT=structured to use the structured error format for all error responses:

Use structuredError() explicitly regardless of format setting:

Paginated response

Response also includes Link: <url>; rel="next", <url>; rel="prev" header (RFC 5988).


All response methods

Success

Method Status Notes
success($data, $message, $status, $meta) 200 Base success
created($data, $message, $meta, $location) 201 Sets Location header
accepted($data, $message, $meta, $location) 202 Sets Location header
noContent() 204 Empty body
paginated($items, $total, $nextLink, $prevLink) 200 OData-lite + Link header
fromPaginator($paginator) 200 From LengthAwarePaginator
fromCursorPaginator($paginator) 200 From CursorPaginator (no @count)

Client errors (4xx)

Method Status
badRequest($message, $errors, $meta) 400
unauthorized($message, $errors, $meta) 401
forbidden($message, $errors, $meta) 403
notFound($message, $errors, $meta) 404
conflict($message, $errors, $meta) 409
gone($message, $errors, $meta) 410
validation($messageOrException, $errors, $meta) 422
unprocessable($message, $errors, $meta) 422
locked($message, $errors, $meta) 423
tooManyRequests($message, $errors, $meta, $retryAfter, $limit, $remaining, $reset) 429

Server errors (5xx)

Method Status
error($message, $status, $errors, $meta) 5xx
notImplemented($message, $errors, $meta) 501
serviceUnavailable($message, $errors, $meta, $retryAfter) 503

ETag / conditional requests


Middleware reference

ForceJsonMiddleware

Forces Accept: application/json so every request — including framework-level errors — returns JSON.

RequestIdMiddleware

Attaches X-Request-ID and X-Correlation-ID to every request and response.

SecurityHeadersMiddleware

Adds X-Content-Type-Options: nosniff, X-Frame-Options: DENY, Cache-Control: no-store, Referrer-Policy: strict-origin.

ApiVersionMiddleware

Reads ?api-version= or Api-Version: header. Returns a structured 400 for unsupported versions.

Config: laravel-api.versioning.supported = ['1.0', '2.0']

DeprecationMiddleware

Signals deprecation and removal date on a route group.

Sets Deprecation: and Sunset: response headers automatically.


Exception rendering

Exception Status
AuthenticationException 401
AuthorizationException 403
ValidationException 422 with full error bag
ModelNotFoundException 404 with model name
HttpException matching status
Throwable 500 (message hidden in production, shown with APP_DEBUG=true)

Only renders for requests that send Accept: application/json or match api/*.


Health check

Enabled by default at GET /_health:


OpenAPI generation

Generate files

Auto-generated spec features

Every generated spec includes:

Runtime endpoints

Schema providers

Operation overrides


Testing with ApiResponseAssertions

Add the trait to your test case for fluent API response assertions:

Available assertions:

Method Description
assertApiSuccess($response, $status) ok=true, envelope structure
assertApiCreated($response) 201 + envelope
assertApiAccepted($response) 202 + envelope
assertApiNoContent($response) 204
assertApiPaginated($response) value + @count
assertApiError($response, $status) ok=false
assertApiValidationError($response, $field) 422 + optional field check
assertApiUnauthorized($response) 401
assertApiForbidden($response) 403
assertApiNotFound($response) 404
assertApiTooManyRequests($response, $retryAfter) 429 + Retry-After
assertStructuredError($response, $code, $status) structured format
assertApiDataKey($response, $key, $value) data.key value
assertApiMeta($response, $key, $value) meta.key value
assertApiHasRequestId($response) X-Request-ID header

Configuration reference

Full config is in config/laravel-api.php. Key sections:

Key Default Description
openapi.enabled true Enable OpenAPI generation
openapi.title app name Spec title
openapi.version 1.0.0 Spec version
openapi.default_path_prefix /api Route prefix filter
openapi.cache.enabled false Cache generated spec
openapi.docs_route.enabled true Serve runtime JSON/YAML
openapi.docs_ui.enabled false Enable Swagger/Redoc UI
response.error_format envelope envelope or structured
response.envelope.* — Configurable response keys
response.pagination.* — OData-lite key names
request_id.enabled true Attach correlation headers
request_id.header X-Request-ID Request ID header name
versioning.enabled false Validate api-version
versioning.supported [] Whitelist (empty = accept all)
exceptions.auto_render false Auto-register exception renderer
health.enabled true Enable health endpoint
health.route _health Health check URL path

Quality checks

Run from the package directory:


Changelog and upgrade

Project documents

Features

Installation (local path repository)

  1. Add path repository in root composer.json:

  2. Require package:

  3. Publish config:

  4. (Optional) Publish docs UI assets:

Commands

Generate both outputs to configured paths:

Generate only JSON:

Generate YAML to custom file:

Limit generation to a prefix:

Generate with route filters:

Runtime endpoints

Optional docs UI route:

Routes are configurable in config/laravel-api.php.

End-to-end quick start

  1. Install the package and publish the config:

  2. Enable the human-readable docs UI in config/laravel-api.php:

  3. Publish the UI assets:

  4. Generate the OpenAPI artifacts:

  5. Open the machine-readable and human-readable endpoints:

The integration guide in docs/PROJECT_INTEGRATION_GUIDE.md demonstrates that full flow with real endpoints and payloads.

API response helpers

Use the responder to avoid repeating JSON response structures in controllers.

Options:

Examples:

Alias support (including user-requested typo compatibility):

Quality and CI

Run package quality checks from the package directory:

GitHub Actions workflow is provided at .github/workflows/laravel-api-quality.yml.

Versioning policy

This package follows Semantic Versioning.

Public API surface is defined in docs/SEMVER_POLICY.md.

Upgrade and changelog

Open source project documents

Documentation map

Release and publishing

Before tagging a release, run:

For monorepo-only usage, keep requiring via path repository. For distribution, publish to Packagist using the process in docs/RELEASE.md.

Phase 2 configuration hooks


All versions of laravel-api with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
illuminate/support Version ^10.0|^11.0|^12.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package yoosuf/laravel-api contains the following files

Loading the files please wait ...