API Response is a Laravel package that provides a collection of reusable tools commonly required when building APIs and backend services.
Instead of repeatedly implementing the same helpers, validation rules, transformers, response formatting, and utility functions across multiple projects, API Response centralizes them into a single package designed to improve consistency, maintainability, and developer productivity.
The package is actively used throughout the ElyerrLabs ecosystem, including OAuth2 Passport Server and related services.
Provides a standardized way to return API responses using the included JsonResponser trait.
Benefits:
- Consistent API responses
- Standardized success and error formats
- Cleaner controllers
- Better frontend integration
- Reduced boilerplate code
Example:
return $this->showOne($user);return $this->showAll($users);return $this->errorResponse(
'Resource not found',
404
);API Response includes reusable validation rules for common scenarios.
Converts and validates boolean values received from forms, APIs, and external services.
Supported examples:
true
false
1
0
Validates monetary values and converts them into integer-based storage formats.
Example:
10.50
Stored as:
1050
This follows the same approach used by payment providers such as Stripe, helping prevent floating-point precision issues.
Ensures a value contains only valid string content.
Useful for:
- Names
- Labels
- Titles
- Categories
Allows validation against values considered empty, undefined, or invalid for your application.
Useful when consuming data from external APIs or user-generated payloads.
Generate transformers using:
php artisan api-response:transformer UserTransformerTransformers help separate data presentation from business logic and create consistent API responses.
Example:
class UserTransformer extends Transformer
{
public function transform(User $user)
{
return [
'id' => (int) $user->id,
'name' => $user->name,
];
}
}The package includes several utility helpers frequently required in Laravel applications.
Examples include:
- Temporary password generation
- Unique code generation
- Date formatting
- Money formatting
- Array transformations
- Request flattening
- Slug generation
- Kebab-case conversion
- Time range validation
- File manipulation helpers
Example:
money_to_cents('10.50');Result:
1050
The package provides reusable utility methods through the Asset helpers.
Common use cases:
- Password generation
- Unique identifiers
- Date formatting
- Array processing
- File operations
- String manipulation
These utilities are designed to eliminate repetitive code commonly found across Laravel projects.
Includes utilities for standardizing exception reporting and API error responses.
This helps maintain consistent error handling throughout your application.
composer require elyerr/api-responsecomposer require elyerr/api-response dev-mainPublish the default resources used by the package.
php artisan api-response:installGenerate a new transformer using the package stub.
php artisan api-response:transformer UserTransformerMost Laravel applications end up implementing the same functionality repeatedly:
- API response formatting
- Validation rules
- Transformers
- Utility helpers
- Date handling
- Money handling
- Data normalization
- Exception formatting
API Response centralizes these concerns into a single package, allowing developers to focus on business logic instead of rewriting infrastructure code.
API Response is intentionally lightweight and extensible.
You can:
- Create your own validation rules
- Extend transformers
- Add custom helpers
- Customize response formats
- Integrate package features into your own architecture
The package is designed to adapt to your workflow rather than forcing a specific development style.
AGPL-3.0