matijajanc / postman by matijajanc

Postman file generator
150
0
1
Package Data
Maintainer Username: matijajanc
Maintainer Contact: matija.janc@gmail.com (Matija Janc)
Package Create Date: 2021-10-29
Package Last Update: 2021-11-02
Language: PHP
License: MIT
Last Refreshed: 2024-04-19 15:14:45
Package Statistics
Total Downloads: 150
Monthly Downloads: 2
Daily Downloads: 1
Total Stars: 0
Total Watchers: 1
Total Forks: 0
Total Open Issues: 0

Postman collection generator

Installation

composer require matijajanc/postman

Laravel

Publish config file

php artisan vendor:publish --provider="Matijajanc\Postman\Providers\PostmanServiceProvider"

Lumen

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

Run command to generate Postman files

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.

Requirements

  • 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/

PHP 8 attributes

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.

Usages

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