Skip to content

📕 Collection of resources to learn RESTful API design in Laravel

License

Notifications You must be signed in to change notification settings

joelbladt/laravel-api-boilerplate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Laravel Logo

Build Status Coveralls License

About Laravel API Boilerplate

This project is a boilerplate setup for building an API with Laravel. It includes various packages and configurations designed to accelerate and standardize development.

Requirements

  • PHP: Version >= 8.2
  • Composer: For managing PHP dependencies
  • Laravel: 11.x

Installation Guide

1. Clone the repository:

git clone https://github.com/joelbladt/laravel-api-boilerplate.git
cd ./laravel-api-boilerplate

2. Install dependencies:

composer install

3. Setting Up Git Hooks: To set up Git hooks for this project, follow these steps:

3.1. Copy Hooks: Copy all custom hooks from the .hooks directory to the .git/hooks directory by running:

cp -r .hooks/* .git/hooks/

3.2. Make Hooks Executable: Ensure all hook scripts are executable:

chmod +x .git/hooks/*

That's it! Your Git hooks are now set up and will run automatically on relevant Git actions (like commits or pushes).

4. Configure environment file: Create a .env file in the root directory based on .env.example, then adjust environment variables (database, API keys, etc.).

5. Generate application key:

php artisan key:generate

6. Run migrations and seeders (if needed):

php artisan migrate --seed

Installed Packages

This project uses additional Laravel packages to enhance the API functionality. Here’s a list of the key packages and how to configure them.

1. darkaonline/l5-swagger

Description: l5-swagger provides an automatically generated Swagger UI, which offers developers a documented overview of all API endpoints. This is especially useful for frontend developers to better understand and test available endpoints and their requirements.

Installation: The package is already installed, but you may need to publish the configurations to customize the documentation.

php artisan vendor:publish --provider "L5Swagger\L5SwaggerServiceProvider"

Accessing Swagger UI: Once installed and configured, the documentation is typically accessible at the following URL: http://localhost/

Configuration:

  • In config/l5-swagger.php, you can adjust various settings like API version, documentation title, and security configurations.
  • l5-swagger integrates with the OpenAPI Specification for auto-generating API documentation.

Usage:

  • Use the Swagger interface to document and test endpoints.
  • Make changes in your controller file comments to reflect them in the Swagger documentation.

Testing

To ensure all features work as expected, you can run unit tests. By default, tests are located in the tests/Feature and tests/Unit directories.

php artisan test

API Documentation

Once configured, l5-swagger provides API documentation through Swagger, detailing all routes, parameters, and response examples.

Working with the Boilerplate

This project follows the Repository Pattern to separate data access logic from business logic, providing a cleaner and more modular code structure. For full instructions on using the Repository Pattern in this boilerplate, please refer to the Developer Guide.

License

This project is licensed under the MIT license. For more information, see the LICENSE file.