Download the PHP package imran/laravel-api-toolkit without Composer

On this page you can find all versions of the php package imran/laravel-api-toolkit. 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-toolkit

Laravel API Toolkit

Standardized JSON API responses and an automatic, environment-aware exception handler for Laravel APIs — built for teams shipping a REST/JSON API to a frontend (Next.js, Vue, mobile, etc.) that needs one predictable response shape, always.

Installation

The service provider and ApiResponse facade are auto-discovered. Publish the config (and optionally the language file) if you want to customize anything:

Response contracts

Success

meta is omitted entirely when empty.

Error

errors is omitted when not applicable. With api-toolkit.debug enabled, error responses also include a debug key (exception, file, line, and trace if show_trace is on) — but only for genuinely uncaught/unmapped exceptions (the 500 fallback). A mapped/known exception (validation, not-found, your own exception_map/ApiException entries, ...) never gets a debug key regardless of debug mode, since its status/message/error_code are already accurate and self-explanatory — debug exists to help diagnose the unexpected, not to duplicate what's already in the response.

Loading / processing (HTTP 202 — for async jobs / polling endpoints)

Paginated success — pass a paginator straight into success():

Works with LengthAwarePaginator (paginate()), the simple Paginator (simplePaginate() — same shape minus total/last_page/nav.last), and CursorPaginator (cursorPaginate() — next_cursor/prev_cursor instead of page numbers), whether passed raw or wrapped in a Resource collection. Set api-toolkit.paginate to false to disable and pass paginators through untouched.

Usage

Facade

Controller trait

Prefer calling these methods directly on the controller instead of importing the facade everywhere:

The trait uses common names (success, error, created, deleted, forbidden, notFound, ...). If a base controller you're adopting this into already defines one of these itself, PHP will raise a "trait method has not been applied, because there are collisions" fatal error. Alias around it:

Global helpers

Throwing typed API errors: ApiException

For business/domain errors, throw ApiException directly instead of round-tripping through exception_map config:

It self-renders into the standard JSON envelope even if auto_register is disabled (Laravel calls an exception's own render() method when it defines one — this runs before the package's exception_map/built-in mapping, so ApiException always wins regardless of that config). Because of this, ApiException always responds with JSON, even for a request that didn't ask for it — only throw it from API code paths.

By default, report() suppresses Laravel's normal exception logging for expected client errors (status < 500) — the same way Laravel itself already treats ValidationException/ModelNotFoundException — while genuine 5xx errors are still logged as usual. Extend ApiException and override report() if you want different behavior.

Automatic exception handling

The moment the package is installed, any exception thrown while handling a request that expects JSON (or matches config('api-toolkit.paths'), api/* by default) is normalized automatically:

Exception Status error_code
ValidationException 422 VALIDATION_ERROR
AuthenticationException 401 UNAUTHENTICATED
AuthorizationException / AccessDeniedHttpException 403 FORBIDDEN
ModelNotFoundException / NotFoundHttpException 404 NOT_FOUND
MethodNotAllowedHttpException 405 METHOD_NOT_ALLOWED
ThrottleRequestsException 429 TOO_MANY_REQUESTS
Any other HttpExceptionInterface its own status looked up from error_codes
Anything else (uncaught 500s) 500 SERVER_ERROR

Requests that don't expect JSON and don't match paths are left completely untouched — your normal Blade error pages keep working.

Adding your own exceptions

Map any exception (including your own domain exceptions) in config/api-toolkit.php without writing any handler code:

If a mapped (or built-in) exception defines its own public errors() method — the same convention ValidationException and Illuminate\Contracts\Validation\Validator already use — its return value is used as the response's errors array automatically:

HTTP headers the exception itself carries are also preserved onto the normalized response — e.g. Retry-After on a throttling exception or Allow on a method-not-allowed exception — matching Laravel's own default behavior.

Disabling auto-registration

If you'd rather wire it up yourself (e.g. you already have a heavily customized Handler.php), set:

and call the renderer manually from your own exception handler:

Configuration reference (config/api-toolkit.php)

Key Default Description
auto_register true Automatically hook into Laravel's exception handler.
paths ['api/*'] Path patterns always treated as API requests.
debug env('API_TOOLKIT_DEBUG', env('APP_DEBUG')) Include exception details on 500s.
show_trace false Include the full stack trace when debug is on.
errors_format flat flat (array of {field, message}) or nested (Laravel default).
paginate true Auto-unwrap paginators passed to success() into data + meta.pagination.
log_unhandled false Log uncaught/unmapped exceptions through this package too. Off by default — Laravel already reports every exception through its own logging independently of this package, so leaving this on would double every log entry. Only turn it on if you've suppressed Laravel's own reporting for these exceptions.
log_channel null Log channel to use when log_unhandled is on (null = default).
messages see config Fallback messages, also translatable via resources/lang/{locale}/api-toolkit.php.
error_codes see config HTTP status → machine-readable error code.
status_messages see config HTTP status → which messages key to use as the default message. Statuses not listed fall back to the status's own standard HTTP reason phrase, so a response is never shipped with an empty message.
exception_map see config Exception class → status/error_code/message.

Message resolution order

For any error response, the message shown is resolved in this order: (1) an explicit $message argument, (2) an exception_map override, (3) the exception's own non-empty message, (4) the status_messages → messages lookup for that HTTP status, (5) the status's standard HTTP reason phrase (e.g. Unprocessable Entity) as the final fallback. A response's message is never empty.

Testing

License

MIT.


All versions of laravel-api-toolkit with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1|^8.2|^8.3|^8.4
illuminate/auth Version ^10.0|^11.0|^12.0|^13.0
illuminate/contracts Version ^10.0|^11.0|^12.0|^13.0
illuminate/database Version ^10.0|^11.0|^12.0|^13.0
illuminate/http Version ^10.0|^11.0|^12.0|^13.0
illuminate/support Version ^10.0|^11.0|^12.0|^13.0
illuminate/validation Version ^10.0|^11.0|^12.0|^13.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 imran/laravel-api-toolkit contains the following files

Loading the files please wait ...