{"id":18575813,"url":"https://github.com/paveldanilin/rest-client","last_synced_at":"2025-10-08T10:16:51.086Z","repository":{"id":55200348,"uuid":"522557982","full_name":"paveldanilin/rest-client","owner":"paveldanilin","description":"REST client for PHP 7.4+","archived":false,"fork":false,"pushed_at":"2024-10-27T04:57:04.000Z","size":76,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"2.0","last_synced_at":"2025-04-06T22:32:18.300Z","etag":null,"topics":["interceptor","json-rest-client","middleware","psr-18","psr-7","rest-client"],"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/paveldanilin.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":"2022-08-08T13:20:31.000Z","updated_at":"2024-10-23T13:11:31.000Z","dependencies_parsed_at":"2024-11-02T05:02:13.261Z","dependency_job_id":null,"html_url":"https://github.com/paveldanilin/rest-client","commit_stats":{"total_commits":23,"total_committers":1,"mean_commits":23.0,"dds":0.0,"last_synced_commit":"a2c1a7ecf61265fe22a582ae8effbb9d588c9282"},"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paveldanilin%2Frest-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paveldanilin%2Frest-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paveldanilin%2Frest-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paveldanilin%2Frest-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/paveldanilin","download_url":"https://codeload.github.com/paveldanilin/rest-client/tar.gz/refs/heads/2.0","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248176957,"owners_count":21060142,"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":["interceptor","json-rest-client","middleware","psr-18","psr-7","rest-client"],"created_at":"2024-11-06T23:22:14.970Z","updated_at":"2025-10-08T10:16:46.033Z","avatar_url":"https://github.com/paveldanilin.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# RestClient\n\nRestClient is [an interface](src/RestClientInterface.php) representing the main entry point for performing REST requests.\n\nRestClient is a handy tool that adds a list of extra features to a Psr/HttpClient (at the same time it is not intended to\nreplace Psr/HttpClient):\n1. Serializer/Deserialize request/response body.\n2. Intercept request (allows to modify request before sending or process a response object).\n3. Retry strategy.\n\n## Install\n\n```shell\ncomposer require paveldanilin/rest-client\n```\n\n## Quick Examples\n\n### Create a new REST client\n\nFor simplicity, we are using a Guzzle HTTP client, but you are free to use any PSR-18 compliant HTTP client.\n\n```php\n// PSR-18 HTTP client\n$httpClient = new GuzzleHttp\\Client([\n    'base_uri' =\u003e 'https://animechan.vercel.app',\n]);\n\n// Serializer\n$serializer = new \\RestClient\\Serialization\\Symfony\\JsonSymfonySerializer();\n\n$restClient = new \\RestClient\\RestClient($httpClient, $serializer);\n```\n\n\n### Define an application response model\n```php\nclass AnimeQuote\n{\n    private string $anime = '';\n    private string $character = '';\n    private string $quote = '';\n\n    public function getAnime(): string\n    {\n        return $this-\u003eanime;\n    }\n\n    public function setAnime(string $anime): void\n    {\n        $this-\u003eanime = $anime;\n    }\n\n    public function getCharacter(): string\n    {\n        return $this-\u003echaracter;\n    }\n\n    public function setCharacter(string $character): void\n    {\n        $this-\u003echaracter = $character;\n    }\n\n    public function getQuote(): string\n    {\n        return $this-\u003equote;\n    }\n\n    public function setQuote(string $quote): void\n    {\n        $this-\u003equote = $quote;\n    }\n}\n```\n\n\n### Get an object\n\nTake a look at [the example](example/anime_quote.php).\n\n```php\n/** @var AnimeQuote|null $quote */\n$quote = $restClient-\u003egetForObject('/api/random', AnimeQuote::class);\n\nprint \"------------------------------------------\\n\";\nprint 'Anime:     ' . $quote-\u003egetAnime() . \"\\n\";\nprint 'Character: ' . $quote-\u003egetCharacter() . \"\\n\";\nprint 'Quote:     ' . $quote-\u003egetQuote() . \"\\n\";\nprint \"------------------------------------------\\n\";\n```\n\n\n### Get a list of objects\n\nTake a look at [the example](example/JsonPlaceholder/print_blog_posts.php).\n\n```php\n/** @var array\u003cApiModel\u003e $models */\n$models = $restClient-\u003egetForObject('/api/models', \\RestClient\\Helpers\\asList(ApiModel::class));\n```\n\n\n### Intercept request\n\nUse case of interceptor:\n- Request header modification\n- Request and response logging\n- Request denial based on certain request parameters\n- Changing the request URL address\n\n\nOut of the box you can use following interceptors:\n* [Log request](src/Interceptor/LogRequestInterceptor.php)\n* [Retry](src/Interceptor/RetryInterceptor.php)\n* [Add header](src/Interceptor/AddHeaderInterceptor.php)\n* [Callable](src/Interceptor/CallableInterceptor.php)\n\n\nDid not find a right interceptor? Do not get upset!\nIt's easy to create a new one, just implement the following interface:\n\n```php\ninterface RequestInterceptorInterface\n{\n    /**\n     * @throws ClientExceptionInterface\n     */\n    public function intercept(RequestInterface $request, ContextInterface $context, RequestExecutionInterface $execution): ResponseInterface;\n}\n```\n\nSet interceptors\n```php\n$restClient-\u003esetInterceptors([\n    new \\RestClient\\Interceptor\\RetryInterceptor(), // \u003c- Retry request in case of [429] or [503] response status\n    new \\RestClient\\Interceptor\\RequestIdInterceptor(), // \u003c- Add Request-Id header (uuid v4)\n    new \\RestClient\\Interceptor\\LogRequestInterceptor($logger), // \u003c- Log before/after and exception\n]);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpaveldanilin%2Frest-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpaveldanilin%2Frest-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpaveldanilin%2Frest-client/lists"}