{"id":15016370,"url":"https://github.com/sudiptochoudhury/php-api-client-forge","last_synced_at":"2025-10-16T18:13:08.159Z","repository":{"id":57060985,"uuid":"140977723","full_name":"sudiptochoudhury/php-api-client-forge","owner":"sudiptochoudhury","description":"Create restful API client in PHP","archived":false,"fork":false,"pushed_at":"2024-04-11T08:26:11.000Z","size":60,"stargazers_count":5,"open_issues_count":1,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-09-25T14:02:33.502Z","etag":null,"topics":["api","api-client","api-consumer","forge","php"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sudiptochoudhury.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-07-14T21:00:31.000Z","updated_at":"2024-04-25T12:09:41.000Z","dependencies_parsed_at":"2024-06-21T20:24:01.553Z","dependency_job_id":null,"html_url":"https://github.com/sudiptochoudhury/php-api-client-forge","commit_stats":null,"previous_names":[],"tags_count":33,"template":false,"template_full_name":null,"purl":"pkg:github/sudiptochoudhury/php-api-client-forge","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sudiptochoudhury%2Fphp-api-client-forge","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sudiptochoudhury%2Fphp-api-client-forge/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sudiptochoudhury%2Fphp-api-client-forge/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sudiptochoudhury%2Fphp-api-client-forge/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sudiptochoudhury","download_url":"https://codeload.github.com/sudiptochoudhury/php-api-client-forge/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sudiptochoudhury%2Fphp-api-client-forge/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279223058,"owners_count":26129314,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-16T02:00:06.019Z","response_time":53,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","api-client","api-consumer","forge","php"],"created_at":"2024-09-24T19:48:45.389Z","updated_at":"2025-10-16T18:13:08.103Z","avatar_url":"https://github.com/sudiptochoudhury.png","language":"PHP","readme":"# php-api-client-forge\n\nCreate restful API client from Postman Collection data (or other sources) in PHP with least code.\n# php-api-client-forge\n\n- Create restful API client class from Postman Collection data (or other sources)  \n- Auto generate class `@method` documentation for phpDoc \n- Auto generate Markdown API Documentation\n \n \n\n[![Latest Stable Version](https://poser.pugx.org/sudiptochoudhury/php-api-client-forge/version)](https://packagist.org/packages/sudiptochoudhury/php-api-client-forge)\n[![Latest Unstable Version](https://poser.pugx.org/sudiptochoudhury/php-api-client-forge/v/unstable)](//packagist.org/packages/sudiptochoudhury/php-api-client-forge)\n[![License](https://poser.pugx.org/sudiptochoudhury/php-api-client-forge/license)](https://packagist.org/packages/sudiptochoudhury/php-api-client-forge)\n[![Total Downloads](https://poser.pugx.org/sudiptochoudhury/php-api-client-forge/downloads)](https://packagist.org/packages/sudiptochoudhury/php-api-client-forge)\n[![composer.lock available](https://poser.pugx.org/sudiptochoudhury/php-api-client-forge/composerlock)](https://packagist.org/packages/sudiptochoudhury/php-api-client-forge)\n\nImport API definitions from Postman exported JSON to a JSON compatible with Guzzle\\Description format \nor pass a `GuzzleHttp\\Command\\Guzzle\\Description` object and \nyour API class is ready to roll. \n\n\u003e As a bonus, you will also get an auto generated API documentation in markdown format. Moreover, you will get a php \nfile with `@method` declarations for phpDoc class documentation. \n\nThis package needs to be used as parent. Extend the `Client` class to make you own API class. \n\n\u003e This is specially \ndesigned to import Postman collection exported as JSON (Collection v2.1 - \n[Schema](https://schema.getpostman.com/json/collection/v2.1.0/collection.json)). \n\n\n\u003ca name=\"basics\"/\u003e\n\n## Basics\n\n```php\n\n\u003c?php\n\nnamespace My\\Namespace\\ApiProvider;\n\nuse SudiptoChoudhury\\Support\\Forge\\Api\\Client as ApiForge;\n\nclass Api extends ApiForge\n{\n\n    protected $DEFAULT_API_JSON_PATH = './config/GuzzleDescription.json';\n    \n    protected $DEFAULTS = [\n        'AuthToken' =\u003e 'xxxxxxxxxxxxxxxxxxxxxxxxxx',\n        'ClientID' =\u003e 'xxxxxxxxxxxxxxx',\n        'client' =\u003e [\n            'base_uri' =\u003e 'https://api.provider.com/api/v1/',\n            'verify' =\u003e false,\n            'headers' =\u003e [\n                'Authorization' =\u003e 'authtoken {{AuthToken}}',\n                'X-clientID' =\u003e \"{{ClientID}}\",\n            ],\n        ],\n    ];\n\n}\n \n```\nThat should be it. Nothing else is required. All the API endpoint will be intelligently converted to functions of this \nclass. For example, if you have an endpoint `[GET]/products`, you will get a `getProducts` function. Here are some more \nexamples:\n\n| HTTP Method | Endpoint | Converted function name | Parameters | Example call |\n|-------------|----------|-------------------------|------------|--------------|\n|GET| /products| `getProducts` | none | `$api-\u003egetProducts()`|  \n|GET| /products/{product_id}| `getProduct` | `product_id` | `$api-\u003egetProduct(['product_id' =\u003e 101])`|  \n|POST| /products| `addProduct` | a list of params  | `$api-\u003eaddProduct($data)`|\n|PUT| /products/{product_id}| updateProduct | `product_id` and a list of other parameters | `$api-\u003eupdateProduct(['product_id' =\u003e 101])`...|\n|DELETE| /products/{product_id}| deleteProduct | `product_id` | `$api-\u003edeleteProduct(['product_id' =\u003e 101])`|\n\nTried best to normalize the singulars and plurals.\n\n\n\u003e There can be cases when the API endpoint structure is same as the another but the data passed to it determines a \ndifferent action altogether. Ideally, this should not happen but not all API enpoints are ideally created.\nSo, an endpoint like `[get]/products?filter_by=active` along with another endpoint `[get]/products` will have the \nsame name. To keep both, the default behaviour is to add an `_` before the duplicate name. However, you can add filters \nor hooks to completely change the duplicate name to something else.  \n\n\n\u003ca name=\"install\"/\u003e\n\n## Installation\n\n\u003ca name=\"requirements\"/\u003e\n\n### Requirements\n\n- Any flavour of PHP 7.0+ should do\n\n\u003ca name=\"install-composer\"/\u003e\n\n### Install With Composer\n\nYou can install the library via [Composer](http://getcomposer.org) by adding the following line to the \n**require** block of your *composer.json* file (replace dev-master with latest stable version):\n\n```\n\"sudiptochoudhury/php-api-client-forge\": \"dev-master\"\n```\n\nor run the following command:\n\n```\ncomposer require sudiptochoudhury/php-api-client-forge\n```\n\n\u003ca name=\"import\"/\u003e\n\n## Importing Postman JSON\n\nExport your Postman Collection using COllecton v2.1 format. It will be exported as JSON. Give the file a \nname, say `postman.json` and keep it inside a folder in your project. \n\nNext, extend `Import` class (recommended) or may use it directly.\n\n#### By Extending the `Import` class\n  \t \n```php\n\u003c?php\nnamespace My\\Namespace\\ApiProvider;\n\nuse SudiptoChoudhury\\Support\\Forge\\Api\\Import as ParentImport;\n\n/**\n * Class Import\n *\n * @package Pour\\Package\\Name\n */\nclass Import extends ParentImport\n{\n\n    protected $DEFAULT_API_JSON_PATH = './config/GuzzleDescription.json';\n    protected $DEFAULT_SOURCE_JSON_PATH = './config/postman.json';\n    \n}\n```\nYou are ready to import. That's pretty much it (though there are tons of configurable options and hooks...\n we will come to that soon).\n\nNow, let's import in some other part of your codebase.\n\n```php\n\u003c?php\n\nuse My\\Namespace\\ApiProvider\\Import;\n...\nnew (Import())-\u003ewriteDefinition();\n...\n\n```\n\nDone!\n\n\n#### Directly using parent class\n\nIt's even simpler (though)\n\n```php\n\u003c?php\n\nuse SudiptoChoudhury\\Support\\Forge\\Api\\Import;\n\n...\nnew (Import([\n   './config/postman.json'\n]))-\u003ewriteDefinition( './config/GuzzleDescription.json');\n...\n```\n\nSimpler, eh!\n\nYou will find a new `.json`, a new `.md` and a new `.php` file to server you well in your API venture forward.\n\nThe `.json` file is obviously based on data structure required to create a `GuzzleHttp\\Command\\Guzzle\\Description` \nobject. \n\nThe `.php` file has phpDoc `@method` definitions and may look something similar to \n\n```php\n\u003c?php\n/** \n * @method\tarray\tgetHostedpage(array $parameters)\tGetting the details of a particular hosted page\n * @method\tarray\tgetHostedpages()\tListing all the hostedpages\n\n```\n You can copy the method definitions parts to yor API class extended from the `Client` class.\n \n The `.md` file is a markdown file with a table containing details of the API functions, equivalent endpoints, \n parameters, default values for parameters (if defined) and description - all derived from the Postman json file.\n   \n  \n\n\u003e However, I would recommend to use the extend option as you will get a plethora of options to hook into various \nsections of parent code while the conversion of the Postman data to Guzzle Description is undergoing. \nYou may want to add default values or change a name or change description or skip some items. \nAll can be done by overriding functions of Import parent class and defining custom filter functions.\n    \n\n\u003ca name=\"filters\"/\u003e\n\n## What are custom filter function?!!!\n\nWell, let's pick an example. Let's say you see you want to change the duplicate function name for `[get]/products` as \nI stated an example in previous section. By default, the duplicate name will be set to `_getProducts` \n(remember? by default adding a `_` before the name). \n\nNow, in your extended `Import` class just define this\n\n```php\n\u003c?php\n\n\t\t/** This is a filter \n\t\t* @param $apiFunctionName\n\t\t* @param array $helperData\n\t \t* @return string\n\t */\n    public function filterFinalName($apiFunctionName, $helperData = [])\n    {\n        if ($apiFunctionName === '_getProducts') {\n            $apiFunctionName = 'getActiveProducts';\n        }\n        return $apiFunctionName;\n    }\n\n```\n\nThis is a filter function. The name must start with `filter` followed by the filter name and can then optionally \nadd an `_` and anything you want after that, just in case you want to define multiple functions for the same filter \n(like - `filterFinalName_xxx` or `filterFinalName_001`).\n\nEach filter function will receive the value to be modified in the first parameter. The optional second parameter \nwill be an associative array of helper data items that may help in determining logic of how the filter can be applied.\nAt times it may also be the source of data to build documentation layouts. For example, the markdown API table is \ngenerated via a default filter. You can override it to generate the API table in your own way. May be you do not like \ntable structure, you may devise you own structure. Sky is the limit. Additionally, there are a lot of filters dedicated\nto create a complete markdown documentation with sections like title, menu, description, table, header, footer, \ninstall, even donate and contact. Just tap into the desired layout filters and fill in your own content.\n\n\nThe table below gives you details of all the filters.\n\n\u003e But before that, you can also do similar things by totally overriding the parent's functions. For example, \n`readApiName`  can be overridden to extend or replace existing logic to detect a function name with your own logic.\nHowever, filters help in changing things in a granular way. There can be 10 filters applied to a single \nfunction you wan to override and you may need to just use one filter out of them instead of writing a big bunch of \noverriding code. Of course, choice is yours.\n\n| Filter Name | Description |\n|-------------|------------- |   \n| Name  | API function name of a single Endpoint |\n| Slug  | A slug derived from API's name defined in Postmam  |\n| FinalName  | API function name after all logic has been applied  |\n| Params  |  Api function parameters |\n| Uri  | Endpoint  |\n| Operation  | Opetaion data of a single endpoint for Guzzle Description  |\n| Title  | Title of the Postman collection  |\n| DocMethodFinalText  | phpDoc method as joined text  |\n| DocMDItem  | Markdown API for single endpoint details as array  |\n| DocMDApiExternalLink  | Markdown's placeholder for link to external (API service provider's) API Documentation  |\n| DocMDEndpoint  | Endpoint of API item in Markdown documentation |\n| DocMDDescription  |  Description of API item in Markdown documentation  |\n| DocMDParams  |  Parameters of API Item Markdown documentation |\n| DocMDParamDefaults  | Default values for parameters of API item Markdown documentation |\n| DocMDLayoutTitle  | Markdown documentation title  |\n| DocMDLayoutSubtitle  | Markdown documentation subtitle  |\n| DocMDLayoutHeader  |  Markdown documentation header |\n| DocMDLayoutMenu  | Markdown documentation menu  |\n| DocMDLayoutDescription  |  Markdown documentation description |\n| DocMDLayoutRequirements  | Markdown documentation  requirements section |\n| DocMDLayoutInstall  | Markdown documentation install section  |\n| DocMDLayoutGetStarted  | Markdown documentation  gettting started section |\n| DocMDLayoutSetup  | Markdown documentation  setup section |\n| DocMDLayoutExamples  | Markdown documentation examples section  |\n| DocMDLayoutTable  |  Markdown documentation API table section - helper data can be iterated to get data in this structure -`[ 'method' =\u003e '\\\u003cfunction name\\\u003e', 'endpoint' =\u003e '\\\u003cendpoint uri\\\u003e', 'parameters' =\u003e [`\\\u003cindexed array\\\u003e`], 'defaults' =\u003e ['\u003cassociative array\u003e'], 'description' =\u003e '\u003capi description\u003e']`  |\n| DocMDLayoutFooter  | Markdown documentation  footer section |\n| DocMDLayoutNotes  |  Markdown documentation notes section |\n| DocMDLayoutReferences  | Markdown documentation references section  |\n| DocMDLayoutContact  |  Markdown documentation contact us section |\n| DocMDLayoutDonate  | Markdown documentation  donate section |\n| DocMDFinalLayoutArray  | All Markdown documentation layouts as array  |\n| DocMDFinalText  |  Full Markdown documentation as text |\n| APIDefinitionFinalJson  | The full Guzzle Description   |\n| DocMethodItem  |  phpDoc method for single endpoint |\n| DocMethodDescription  | Markdown documentation   |\n| DocMethodFinalArray  | All phpDoc methods as array  |\n| DocMethodParams  | Parameters for phpDoc  |\n| DocMethodData  | What needs to shown in the parenthesis of the method signature in phpDoc |\n| DocMethodSignature  | Full single method signature for phpDoc |\n| GroupName  |  Postman Collection's Group Name |\n| GroupDescription  | Post Collection's Description  |\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsudiptochoudhury%2Fphp-api-client-forge","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsudiptochoudhury%2Fphp-api-client-forge","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsudiptochoudhury%2Fphp-api-client-forge/lists"}