composer require matijajanc/postman
Publish config file
php artisan vendor:publish --provider="Matijajanc\Postman\Providers\PostmanServiceProvider"
add below line to bootstrap/app.php
$app->register(Matijajanc\Postman\Providers\PostmanLumenServiceProvider::class);
Publish config file
cp vendor/matijajanc/postman/config/postman.php config/postman.php
php artisan postman:generate
This command generates 2 files:
- postman-environment.json (where variables are defined)
- postman.json (where all API routes are defined)
Currently it supports bearer token authorization, if you have other wishes please create new issue or pull request on github and I'll add/extend it.
- Laravel 8 or Lumen 8 (it works with older version of Laravel/Lumen also, but you need to provide "method" property in Postman attribute definition)
- PHP ^8.0
- If you want to use JWT bearer token then you need to configure it first https://jwt-auth.readthedocs.io/en/develop/laravel-installation/
I used new PHP 8 attributes feature to define new properties I use for postman file generator. This is not needed to define for GET, DELETE routes, you provide this Postman attribute only where you want your custom request payload POST, PUT.
If no method is provided it calls default factory "definition" method
#[Postman(['factory' => ContractFactory::class])]
public function createContract(Request $request): JsonResponse
You can override which methods get called with additional "method" property
#[Postman(['factory' => ContractFactory::class, 'method' => 'postCreateContract'])]
public function createContract(Request $request): JsonResponse
You can override body type with property "mode"
#[Postman(['factory' => ContractFactory::class, 'method' => 'postCreateContract', 'mode' => 'raw'])]
public function createContract(Request $request): JsonResponse