Download the PHP package alexpensato/laravel-api-maker without Composer
On this page you can find all versions of the php package alexpensato/laravel-api-maker. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download alexpensato/laravel-api-maker
More information about alexpensato/laravel-api-maker
Files in alexpensato/laravel-api-maker
Package laravel-api-maker
Short Description Automate the generation of your REST APIs
License MIT
Homepage https://github.com/alexpensato/laravel-api-maker
Informations about the package laravel-api-maker
Laravel Api Maker
Automate the generation of your REST APIs with the console generator command make:api
Introduction
This package is an extended version of the laravel-api-generator package. It includes a completely rewritten BaseController, now renamed to ApiController. This package also presents two new controller types: ReadOnlyController, for APIs that don't need writing capabilities; and WebController, for applications that need support for frontend scaffolding views.
This package relies on the Repository Design Pattern, which means that Controllers will access Models through a Repository interface, which provides better separation of concerns for data access methods and business rules. This repository implementation was inspired by Connor Leech's and Jeff Decena's articles.
This package also uses Codeception/Specify and Codeception/Verify packages to get you started with BDD-style unit testing.
This enhanced version of the console generator creates the following files for each Model in one single command:
-
ApiController extended class
-
Fractal Transformer class
-
Repository interface
-
Repository implementation class
- Unit test file configured for BDD
It also modifies the following configuration files:
-
Adds routes to routes/api.php
- Adds repository binding to ApiServiceProvider
This package was designed to get you started with professional REST API best practices.
Compatibility
Laravel API Maker | Laravel |
---|---|
1.0.x | 5.6 |
1.1.x | 5.7 |
Installation
Step 1 - Run
Step 2 - Copy the ApiServiceProvider
class to app/Providers
folder:
and check what you got there.
Step 3 - Register the service providers in the config/app.php
configuration file
Step 4 - Laravel already provides an API routes file. To correctly configure the console generator automation process,
you need to choose one of the routing templates presented in vendor/alexpensato/laravel-api-maker/templates/routes/api.php
,
and then copy it to your project's api routing file.
For instance, copy the code below to the end of your routes/api.php
project file.
It will allow the console generator to automatically inject resources routes to the api routing file.
Usage
Generator
The only console command that is added and needed is .
Imagine you need to create a rest api to list/create/update etc. users from users table. To achieve that you need to do lots of boilerplate operations - create controller, transformer, repository, unit testing, set up needed routes and configuring repository binding.
does all the work for you.
It is important to notice that this command assumes that Model has already been created in the Models
folder.
For instance, you can create a Model using the following command:
Conventions
You may have noticed that the Controller
which has just been generated includes two public methods: __constructor()
and transformer()
.
That's because those methods are the only thing that you need in your controller to set up a basic REST API.
The list of routes that are available out-of-the-box:
GET api/v1/users
GET api/v1/users/{id}
POST api/v1/users
PUT api/v1/users/{id}
DELETE api/v1/users/{id}
Request and response formats are JSON. Response format is defined by Fractal.
Fractal includes are supported via $_GET['include']
.
Validation rules for create and update can be set by overwriting rulesForCreate
and rulesForUpdate
in your controller.
Contributions
…are always welcome. Don’t hesitate to submit a bug report or a pull request.
When filling a bug report or submitting a new feature, please try including supporting test cases.
License
This project is licensed under MIT license.
Although it is a tested package, use at your risk!
All versions of laravel-api-maker with dependencies
ext-json Version ^1.6
illuminate/support Version ^5.6
guzzlehttp/guzzle Version ^6.3
league/fractal Version ^0.17
codeception/specify Version ^1.1
codeception/verify Version ^1.0