Download the PHP package mhasnainjafri/restapikit without Composer
On this page you can find all versions of the php package mhasnainjafri/restapikit. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mhasnainjafri/restapikit
More information about mhasnainjafri/restapikit
Files in mhasnainjafri/restapikit
Package restapikit
Short Description Unlock the full potential of your REST API development with RestApiKit. This powerful toolkit offers a variety of utilities to simplify the process of creating, testing, and managing REST APIs. From automatic documentation generation to built-in validation, RestApiKit provides a seamless workflow for developers looking to build reliable and scalable APIs with ease. Focus more on the logic, and let RestApiKit handle the heavy lifting.
License MIT
Homepage https://github.com/mhasnainjafri/restapikit
Informations about the package restapikit
Introduction
The mhasnainjafri/restapikit
package is a Laravel-based toolkit designed to simplify the development of RESTful APIs.
It provides a uniform structure for handling responses, exceptions, file uploads, authentication, and more. This package
is ideal for developers looking to streamline API development while adhering to best practices.
Features
- Uniform API Responses: Standardized success, error, and paginated responses.
- Exception Handling: Beautifully formatted error responses for various exception types.
- File Management: Easy file upload, deletion, and URL generation.
- Built-in Authentication: Includes login, registration, password reset (via email or OTP), and email verification.
- Caching: Simplified caching for API responses.
- Customizable HTTP Status Codes: Predefined constants for common HTTP status codes.
Installation
You can install the package via Composer:
Usage
Extending the RestController
To use the package, extend your controller from Mhasnainjafri\RestApiKit\Http\Controllers\RestController
. This
provides access to the package's built-in methods for handling responses, exceptions, and more.
Functionalities
1. Uniform API Responses
The package provides a consistent structure for API responses. For example:
Success Response
Paginated Response
If $data
is paginated, the response will automatically include pagination metadata:
Alternatively, you can explicitly return a paginated response:
2. Exception Handling
The package simplifies exception handling by providing pre-defined methods for common scenarios:
General Exception
Validation Exception
Unauthorized Access
Server Error
3. File Management
The package includes utilities for file uploads, deletions, and URL generation.
Upload a File
Delete a File
Generate File URL
4. Caching API Responses
The cacheResponse
method allows you to cache API responses for a specified duration.
Example:
1. Response Handling Without Controller Extension
The package provides a standalone API response helper for developers who prefer not to extend the RestController
:
Success Response
Paginated Response
If $data
is paginated, the response will automatically include pagination metadata:
Alternatively, explicitly return a paginated response:
2. Exception Handling
Simplified exception handling with pre-defined methods for common scenarios:
General Exception
Validation Exception
Unauthorized Access
Server Error
3. File Management
Built-in utilities for managing file uploads, deletions, and generating file URLs.
Upload a File
Delete a File
Generate File URL
4. Caching API Responses
Effortlessly cache API responses using the cacheResponse
method or the API
facade.
Example with $this
:
Example with API
Facade:
Clear Cache:
Notes
By offering both RestController
methods and the API
facade, this package empowers developers with flexible options
to build robust APIs. Whether you prefer extending the controller or using standalone helpers, the toolkit adapts to
your workflow.
5. Built-in Authentication
The package includes pre-defined routes and methods to simplify common authentication tasks, ensuring seamless integration into your application.
Available Routes
To enable authentication routes, include the following line in your api.php
:
Customizing Routes
You can specify only the required routes:
Supported Authentication Routes
The following routes are available by default:
login
register
forgotPassword
resetPassword
verifyEmail
sendOtp
verifyOtp
changePassword
Postman Collection
A Postman collection is available to test the authentication endpoints. Download the Postman Collection here.
Authentication Methods
The package supports both Laravel Passport and Laravel Sanctum for authentication. To set up the desired method, run the following command:
Publishing Authentication Controllers
You can customize authentication controllers by publishing them to your project. Run the command below:
This will generate authentication controllers in the following directory:
After publishing the controllers, update the config/restify.php
file to define the correct namespace for your
authentication controllers.
6. HTTP Status Codes
The package includes a predefined API
class with constants for common HTTP status codes:
Constants
APITOOLKIT provides various HTTP status codes as constants for convenience:
API::SUCCESS
: 200API::CREATED
: 201API::NO_CONTENT
: 204API::BAD_REQUEST
: 400API::UNAUTHORIZED
: 401API::FORBIDDEN
: 403API::NOT_FOUND
: 404API::METHOD_NOT_ALLOWED
: 405API::UNPROCESSABLE_ENTITY
: 422API::INTERNAL_SERVER_ERROR
: 500API::NOT_IMPLEMENTED
: 501API::BAD_GATEWAY
: 502API::SERVICE_UNAVAILABLE
: 503
7. Custom Macros
You can define custom macros for reusable functionality. For example:
Example Macro:
Todo list
- Logger
Testing
To run the package's tests, use the following command:
Contributing
Contributions are welcome! Please see the CONTRIBUTING file for details.
Security
If you discover any security-related issues, please email [email protected]
instead of using the issue
tracker.
License
This package is open-sourced software licensed under the MIT License. See the LICENSE file for more details.
Credits
- Author: Muhammad Hasnain
- Contributors: All Contributors
This package boilerplate was generated using the Laravel Package Boilerplate.
All versions of restapikit with dependencies
illuminate/database Version ^10.0|^11.0|^12.0
illuminate/http Version ^10.0|^11.0|^12.0
illuminate/support Version ^10.0|^11.0|^12.0