fixwa/http-client-collection-generator

1.3 2022-09-30 18:12 UTC

This package is auto-updated.

Last update: 2024-09-29 06:20:30 UTC


README

此工具是为了方便生成与HTTP-Clients/API-Clients(如PostmanInsomnia)兼容的导入文件(JSON格式),以便程序性地收集请求并自动化文档或分析任务。

目前仅支持INSOMNIA。

安装和用法

composer require --dev fixwa/http-client-collection-generator
$generator = new Fixwa\HttpClientCollectionGenerator\Insomnia\Generator();

$generator->name('The Collection')
    ->group('Pokedex API')
    ->addRequest([
        'name' => 'Get Vaporeon Info',
        'url' => 'https://pokeapi.co/api/v2/pokemon/vaporeon',
        'method' => 'GET',
        'description' => 'Obtain information about the gorgeous Vaporeon'
    ]);
$generator->generateJson();

上面的代码将返回一个可以直接在Insomnia中使用的JSON字符串,可以通过剪贴板导入或保存到文件,然后使用以下选项导入:创建 -> 从...导入

Import Insomnia

对于给定的示例,导入的集合应如下所示

Imported Insomnia

待办事项(预计完成时间:2099年)

这是一个非常基础的版本,将满足基本需求。待实现的功能包括

  • 输出到文件。
  • 直接从php-curl扩展导入请求。
  • 直接从Guzzle导入请求。
  • 支持其他主要HTTP客户端(Postman,Testfully.io,Thunder)。