Download the PHP package arpanpatoliya/response without Composer
On this page you can find all versions of the php package arpanpatoliya/response. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download arpanpatoliya/response
More information about arpanpatoliya/response
Files in arpanpatoliya/response
Package response
Short Description A simple Laravel package for standardized API responses
License MIT
Homepage https://github.com/arpanpatoliya/response
Informations about the package response
Laravel Response Package
A comprehensive Laravel package for standardized API responses with full HTTP status code coverage and response macros.
๐ Table of Contents
- Features
- Installation
- Quick Start
- Usage
- HTTP Status Codes
- Response Format
- Examples
- Testing
- Contributing
- License
โจ Features
- ๐ 76 Response Macros - Complete HTTP status code coverage
- ๐ Standardized Format - Consistent JSON response structure
- ๐ฏ Easy to Use - Simple, intuitive API
- ๐ง Flexible - Custom status codes and messages
- ๐ Validation Support - Built-in validation error handling
- ๐ฑ Pagination Support - Easy paginated responses
- ๐ท๏ธ Metadata Support - Add custom metadata to responses
- ๐ Logging Integration - Chainable logging for responses
- ๐งช Fully Tested - Comprehensive test coverage
- ๐ Well Documented - Complete documentation and examples
- โก Lightweight - Minimal overhead, maximum functionality
๐ ๏ธ Installation
-
Install the package via Composer:
- The service provider will be automatically registered via Laravel's package discovery.
๐ Quick Start
๐ Usage
Basic Success Responses
Error Responses
Validation Responses
Advanced Responses
Logging Integration
The package provides a chainable log() method to log responses to Laravel's logging system. By default, logs are written to the default logging channel.
Log Parameters:
$channel(optional): Specify a custom logging channel. If not provided, uses the default channel.$level(optional): PSR-3 log level (emergency,alert,critical,error,warning,notice,info,debug). Defaults toinfo.$message(optional): Custom log message. Defaults to'API response'.$context(optional): Additional context array to include in the log entry.
Log Context: The log automatically includes:
status: HTTP status codepayload: Response payload/data- Any additional context you pass
๐ HTTP Status Codes
1xx Informational
| Macro | Status | Description |
|---|---|---|
continue() |
100 | Continue |
switchingProtocols() |
101 | Switching Protocols |
processing() |
102 | Processing |
earlyHints() |
103 | Early Hints |
2xx Success
| Macro | Status | Description |
|---|---|---|
ok() |
200 | OK |
success() |
200 | Success with data |
successMessage() |
200 | Success message only |
created() |
201 | Created |
accepted() |
202 | Accepted |
nonAuthoritativeInformation() |
203 | Non-Authoritative Information |
noContent() |
204 | No Content |
resetContent() |
205 | Reset Content |
partialContent() |
206 | Partial Content |
multiStatus() |
207 | Multi-Status |
alreadyReported() |
208 | Already Reported |
imUsed() |
226 | IM Used |
3xx Redirection
| Macro | Status | Description |
|---|---|---|
multipleChoices() |
300 | Multiple Choices |
movedPermanently() |
301 | Moved Permanently |
found() |
302 | Found |
seeOther() |
303 | See Other |
notModified() |
304 | Not Modified |
useProxy() |
305 | Use Proxy |
temporaryRedirect() |
307 | Temporary Redirect |
permanentRedirect() |
308 | Permanent Redirect |
4xx Client Errors
| Macro | Status | Description |
|---|---|---|
badRequest() |
400 | Bad Request |
unauthorized() |
401 | Unauthorized |
paymentRequired() |
402 | Payment Required |
forbidden() |
403 | Forbidden |
notFound() |
404 | Not Found |
methodNotAllowed() |
405 | Method Not Allowed |
notAcceptable() |
406 | Not Acceptable |
proxyAuthenticationRequired() |
407 | Proxy Authentication Required |
requestTimeout() |
408 | Request Timeout |
conflict() |
409 | Conflict |
gone() |
410 | Gone |
lengthRequired() |
411 | Length Required |
preconditionFailed() |
412 | Precondition Failed |
payloadTooLarge() |
413 | Payload Too Large |
uriTooLong() |
414 | URI Too Long |
unsupportedMediaType() |
415 | Unsupported Media Type |
rangeNotSatisfiable() |
416 | Range Not Satisfiable |
expectationFailed() |
417 | Expectation Failed |
imATeapot() |
418 | I'm a teapot |
misdirectedRequest() |
421 | Misdirected Request |
unprocessableEntity() |
422 | Unprocessable Entity |
locked() |
423 | Locked |
failedDependency() |
424 | Failed Dependency |
tooEarly() |
425 | Too Early |
upgradeRequired() |
426 | Upgrade Required |
preconditionRequired() |
428 | Precondition Required |
tooManyRequests() |
429 | Too Many Requests |
requestHeaderFieldsTooLarge() |
431 | Request Header Fields Too Large |
unavailableForLegalReasons() |
451 | Unavailable For Legal Reasons |
5xx Server Errors
| Macro | Status | Description |
|---|---|---|
internalServerError() |
500 | Internal Server Error |
serverError() |
500 | Server Error (alias) |
notImplemented() |
501 | Not Implemented |
badGateway() |
502 | Bad Gateway |
serviceUnavailable() |
503 | Service Unavailable |
gatewayTimeout() |
504 | Gateway Timeout |
httpVersionNotSupported() |
505 | HTTP Version Not Supported |
variantAlsoNegotiates() |
506 | Variant Also Negotiates |
insufficientStorage() |
507 | Insufficient Storage |
loopDetected() |
508 | Loop Detected |
notExtended() |
510 | Not Extended |
networkAuthenticationRequired() |
511 | Network Authentication Required |
Utility Methods
| Macro | Status | Description |
|---|---|---|
errorMessage() |
200 | Basic error message |
error() |
Variable | Error with custom status |
validationFailure() |
422 | Validation errors |
custom() |
Variable | Custom response |
paginated() |
200 | Paginated response |
withMeta() |
200 | Response with metadata |
updated() |
200 | Resource updated |
deleted() |
200 | Resource deleted |
Logging Method
| Method | Description |
|---|---|
log() |
Chainable logging method for responses. Supports custom channel, level, message, and context. |
๐ Response Format
Success Response
Error Response
Paginated Response
Response with Metadata
๐ก Examples
Complete User Controller Example
Advanced Usage Examples
๐งช Testing
To run the tests for this package:
Or run PHPUnit directly:
The tests cover all response macros, ensuring they return the correct status codes and response formats.
Test Coverage
- โ All HTTP status code macros (100+ methods)
- โ Response format validation
- โ Status code verification
- โ Error handling
- โ Validation responses
- โ Pagination responses
- โ Metadata responses
- โ Custom responses
- โ Logging integration
๐ค Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Development Setup
- Fork the repository
- Clone your fork
- Install dependencies:
composer install - Run tests:
composer test - Make your changes
- Add tests for new features
- Submit a pull request
๐จโ๐ป Author
Arpan Patoliya
- Email: [email protected]
- GitHub: @arpanpatoliya
- LinkedIn: Arpan Patoliya
About the Author
Arpan is a passionate Laravel developer with expertise in building robust and scalable web applications. This package was created to provide a comprehensive solution for standardized API responses in Laravel applications.
๐ License
The MIT License (MIT). Please see License File for more information.
Made with โค๏ธ by Arpan Patoliya
If you find this package helpful, please consider giving it a โญ on GitHub!