hafizmmoaz/laravel-rest-api

A minimal, reusable REST API toolkit for Laravel: consistent JSON responses, a typed exception hierarchy, and base API model/controller.

Maintainers

Package info

github.com/HafizMMoaz/laravel-rest-api

pkg:composer/hafizmmoaz/laravel-rest-api

Statistics

Installs: 2

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-06-29 10:12 UTC

This package is auto-updated.

Last update: 2026-06-29 10:23:00 UTC


README

A minimal, reusable REST API toolkit for Laravel.

Namespace: HafizMMoaz\RestApi

Provides:

  • ApiResponseApiResponse::success($data, $message) / ApiResponse::error($message, $status, $code, $details) for consistent JSON envelopes.
  • A typed exception hierarchy under HafizMMoaz\RestApi\ExceptionsApiException (base) plus ResourceNotFoundException, RelatedResourceNotFoundException, ValidationException, UnauthorizedException, UnauthenticationException. Each carries an HTTP status code and renders to a JSON error response.
  • ApiModel / ApiController — thin base classes to group API resources/endpoints.

Installation

composer require hafizmmoaz/laravel-rest-api

The service provider HafizMMoaz\RestApi\Providers\ApiServiceProvider is auto-discovered. It registers a renderer so any thrown ApiException is returned as its JSON error response automatically.

Usage

use HafizMMoaz\RestApi\ApiResponse;
use HafizMMoaz\RestApi\Exceptions\ResourceNotFoundException;

return ApiResponse::success($user, 'OK');

throw new ResourceNotFoundException('User not found');

License

MIT — see LICENSE.