{"id":17170317,"url":"https://github.com/nahid/apiz","last_synced_at":"2025-07-07T06:33:18.408Z","repository":{"id":22568307,"uuid":"96706966","full_name":"nahid/apiz","owner":"nahid","description":"APIZ is a PHP HTTP client development kit","archived":false,"fork":false,"pushed_at":"2024-12-18T12:39:49.000Z","size":360,"stargazers_count":59,"open_issues_count":1,"forks_count":13,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-24T13:09:40.368Z","etag":null,"topics":["api","api-boilerplate","api-client","boilerplate","php","php-api-clients"],"latest_commit_sha":null,"homepage":"","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/nahid.png","metadata":{"files":{"readme":"readme.md","changelog":null,"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":"2017-07-09T19:38:43.000Z","updated_at":"2025-02-06T04:37:56.000Z","dependencies_parsed_at":"2024-12-28T04:00:25.934Z","dependency_job_id":null,"html_url":"https://github.com/nahid/apiz","commit_stats":{"total_commits":114,"total_committers":8,"mean_commits":14.25,"dds":"0.42105263157894735","last_synced_commit":"884f21193f42008f69a626438c15a08c2e20700c"},"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"purl":"pkg:github/nahid/apiz","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nahid%2Fapiz","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nahid%2Fapiz/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nahid%2Fapiz/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nahid%2Fapiz/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nahid","download_url":"https://codeload.github.com/nahid/apiz/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nahid%2Fapiz/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261901495,"owners_count":23227614,"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","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-boilerplate","api-client","boilerplate","php","php-api-clients"],"created_at":"2024-10-14T23:29:32.317Z","updated_at":"2025-07-07T06:33:18.378Z","avatar_url":"https://github.com/nahid.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# APIZ\n\nAPIZ is a PHP API Client Development Kit, it helps you to manage HTTP API call in OOP way. You can easily handle and isolate all kinds of REST API calls and their responses by using this package.\n\n## Requirements\n\n- PHP \u003e= 5.5.9\n\n## Installations\n\n```shell\ncomposer require nahid/apiz\n```\n\n## Configurations\n\nThere are no extra configurations for this package.\n\n## Usage\n\nLets see an example to consume API from https://reqres.in.\n\nSuppose you need to create several API services for your project. Your service directory is\n`app/Services`. Now we are going to develop a service for https://reqres.in and make a class file `ReqResApiService.php`\nwhich will extend `\\Apiz\\AbstractApi` class.\n\n```php\nnamespace App\\Services;\n\nuse Apiz\\AbstractApi;\n\nclass ReqResApiService extends AbstractApi\n{\n    protected function getBaseURL()\n    {\n        return 'https://reqres.in';\n    }\n}\n```\n\n`getBaseURL()` is an abstract method of the `AbstractApi` class. You need to override this method to set the proper base URL for your API.\n\nFew APIs have a common prefix in their URL. Like, here `reqres.in` have a prefix `api` on every endpoint. \nSo, we'll override the `getPrefix()` method to define the Prefix.\n\n```php\nnamespace App\\Services;\n\nuse Apiz\\AbstractApi;\n\nclass ReqResApiService extends AbstractApi\n{\n    protected function getBaseURL()\n    {\n        return 'https://reqres.in';\n    }\n\n    protected function getPrefix()\n    {\n        return 'api';\n    }\n}\n```\n\nNow let's make a method to get all users info.\n\n```php\nnamespace App\\Services;\n\nuse Apiz\\AbstractApi;\n\nclass ReqResApiService extends AbstractApi\n{\n    protected function getBaseURL()\n    {\n        return 'https://reqres.in';\n    }\n\n    protected function getPrefix()\n    {\n        return 'api';\n    }\n\n    public function getAllUsers()\n    {\n        $response = $this-\u003eget('users');\n\n        if ($response-\u003egetStatusCode() === 200) {\n            return $response()-\u003etoArray();\n        }\n\n        return [];\n    }\n}\n```\nSo, we are basically making a `GET` request to the URL `https://reqres.in/api/users`.\n\nSee, how easy it is to manage an API now?\n\nLet's see another example.\n\n## Post Request with Form Params\n\n```php\npublic function createUser(array $data)\n{\n    $response = $this-\u003ewithFormParams($data)\n            -\u003epost('create');\n\n    if ($response-\u003egetStatusCode() === 201) {\n        return $response()-\u003etoArray();\n    }\n\n    return null;\n}\n```\n\n## Default Headers\n\nSometimes we need to bind some headers with all the requests. Suppose if you want to deal with the Github API, you have to send `access_token` in every request with the headers.\nSo APIZ provide you a handy way to deal with this problem. Just override `AbstractApi::getDefaultHeaders()`.\n\n\n```php\nprotected function getDefaultHeaders()\n{\n    return [\n        'access_token' =\u003e $_ENV['GITHUB_ACCESS_TOKEN'],\n    ];\n}\n```\n\nCool, right?\n\nYou can easily use all HTTP verbs like `get`, `post` etc. It's totally hassle free. \nSee more examples in the [Examples Folder](./Examples).\n\n## Query over Response Data\n\nSometimes we receive huge payload as a response from the APIs. \nIt's quite daunting to parse proper data from that big payload.\n\nNo worries!\nWe're using a powerful Query parser, named [QArray](https://github.com/nahid/qarray) by default to parse and query over the Response data.\n\nLet's see how we can use this parser to parse the response we got for `getAllUsers` method from our previous example.\n\n```php\npublic function getFirstUser()\n{\n    $users = $this-\u003eget('users');\n    return $users-\u003equery()-\u003efrom('data')-\u003efirst();\n}\n```\n\nWe're getting list of users in the `data` key in the response. From that we're collecting the first data.\nSee, how easy it is!\n\nYou can find detail usage of the QArray [here](https://github.com/nahid/qarray).\n\nAdditionally, there is a secret sauce for you. \n\nIf you don't want to query like: `$users-\u003equery()`, you can just do it like this: `$users()`. That means the response object is invokable and behave exactly like calling the `query()` method.\n\nYou're welcome. :D \n\n## Overriding HTTP Client\n\nBy default we are using `Guzzle` as our HTTP Client. But you are not bound to use this. You can easily use your own PSR7 supported HTTP Client with `Apiz`.\nJust pass an instance of your HTTP Client to our `setClient()` method.\nSee an example [here](./Examples/API%20with%20Different%20Client).\n\nHere is our GuzzleClient to get an idea how your Client should look like:\n```php\n\u003c?php\n\nnamespace Apiz\\Http\\Clients;\n\nuse Apiz\\Http\\AbstractClient;\nuse GuzzleHttp\\Client;\nuse GuzzleHttp\\Psr7\\Request;\nuse GuzzleHttp\\Psr7\\Response;\nuse GuzzleHttp\\Psr7\\Uri;\nuse GuzzleHttp\\Exception\\GuzzleException;\nuse Psr\\Http\\Message\\ResponseInterface;\n\n// Your client must extend the `AbstractClient`\nclass GuzzleClient extends AbstractClient\n{\n    public function getRequestClass()\n    {\n        // Return the Request class name of your PSR7 supported Client\n        // This Request class must implement the Psr\\Http\\Message\\RequestInterface\n        return Request::class;\n    }\n\n    public function getResponseClass()\n    {\n        // Return the Response class name of your PSR7 supported Client\n        // This Response class must implement the Psr\\Http\\Message\\ResponseInterface        \n        return Response::class;\n    }\n\n    public function getUriClass()\n    {\n        // Return the Uri class name of your PSR7 supported Client\n        // This Uri class must implement the Psr\\Http\\Message\\UriInterface        \n        return Uri::class;\n    }\n\n    /**\n     * @param mixed ...$args\n     * @return ResponseInterface\n     * @throws GuzzleException\n     */\n    public function send(...$args)\n    {\n        // In this method, implement how your Client execute the Request sending\n        $client = new Client();\n\n        return $client-\u003esend(... $args);\n    }\n}\n```\n\n## List of methods for common HTTP verbs\n\n- `get(string $uri)`\n- `post(string $uri)`\n- `put(string $uri)`\n- `delete(string $uri)`\n- `head(string $uri)`\n- `options(string $uri)`\n\n## List of Available methods\n\n- `getPrefix():string`: override this method to define the common prefix, if you need it\n- `setClient($client)` : pass a PSR7 supported Client instance, only if you need to override the default Guzzle HTTP Client\n- `withFormParams(array)`: pass Form parameters data for requests like POST, PATCH, UPDATE\n- `withHeaders(array)`: pass Header data\n- `withQueryParams(array)`: pass Query Parameter data\n- `withFormData(array)`: pass Multipart form data\n- `getDefaultHeaders():array`: override to define default Headers, if you have any\n- `getDefaultQueries():array`: override to define default queries, if you have any\n- `skipDefaultHeaders(bool)`\n- `skipDefaultQueries(bool)`\n- `allowRedirects(array)`\n- `basicAuth(string $username, string $password [, array $options])`\n- `body(string)`: Set request body\n- `json(array)`: Set JSON data to be passed as Request Body\n- `file(string $name, string $file_path, string $filename [, array $headers])`\n- `params(array $params)`\n\n\n### Contribution\n\nFeel free send feedback and issues. Contributions to improve this package is most welcome too. ","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnahid%2Fapiz","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnahid%2Fapiz","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnahid%2Fapiz/lists"}