{"id":13622426,"url":"https://github.com/tebru/retrofit-php","last_synced_at":"2025-04-15T06:30:28.584Z","repository":{"id":26017593,"uuid":"29460280","full_name":"tebru/retrofit-php","owner":"tebru","description":"Retrofit implementation in PHP.  A REST client for PHP.","archived":false,"fork":false,"pushed_at":"2024-07-12T12:07:09.000Z","size":1146,"stargazers_count":157,"open_issues_count":5,"forks_count":23,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-03-06T13:21:28.561Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tebru.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","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":"2015-01-19T08:07:08.000Z","updated_at":"2024-11-12T19:55:42.000Z","dependencies_parsed_at":"2024-08-01T21:54:27.074Z","dependency_job_id":null,"html_url":"https://github.com/tebru/retrofit-php","commit_stats":{"total_commits":267,"total_committers":11,"mean_commits":"24.272727272727273","dds":"0.16104868913857673","last_synced_commit":"dbd1c4a2cf8c879afbd8e85d40137d8ef5f53a15"},"previous_names":[],"tags_count":56,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tebru%2Fretrofit-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tebru%2Fretrofit-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tebru%2Fretrofit-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tebru%2Fretrofit-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tebru","download_url":"https://codeload.github.com/tebru/retrofit-php/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248543854,"owners_count":21121838,"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":[],"created_at":"2024-08-01T21:01:18.969Z","updated_at":"2025-04-15T06:30:28.571Z","avatar_url":"https://github.com/tebru.png","language":"PHP","funding_links":[],"categories":["超文本传输协议 HTTP","Table of Contents","PHP","目录"],"sub_categories":["HTTP","HTTP客户端 HTTP Client","Globalization"],"readme":"Retrofit PHP\n============\n\n[![Build Status](https://travis-ci.org/tebru/retrofit-php.svg?branch=master)](https://travis-ci.org/tebru/retrofit-php)\n[![Code Coverage](https://scrutinizer-ci.com/g/tebru/retrofit-php/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/tebru/retrofit-php/?branch=master)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/tebru/retrofit-php/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/tebru/retrofit-php/?branch=master)\n[![SensioLabsInsight](https://insight.sensiolabs.com/projects/d2188bf8-8248-4df6-8bc5-8150fc0b8898/mini.png)](https://insight.sensiolabs.com/projects/d2188bf8-8248-4df6-8bc5-8150fc0b8898)\n\nRetrofit is a type-safe REST client. It is blatantly stolen from\n[square/retrofit](https://github.com/square/retrofit) and implemented in\nPHP.\n\n❗UPGRADE NOTICE❗\n----------------\n\n**Version 3 introduces many breaking changes. Please review the\n[upgrade guide](docs/upgrade_2_3.md) before upgrading.**\n\nOverview\n--------\n\n*The following is for version 3, please check out the corresponding tag\nfor version 2 documentation*\n\nRetrofit allows you to define your REST API with a simple interface. The\nfollow example will attempt to display a typical use-case, but requires\ntwo additional libraries. The first uses Guzzle to make http requests as\nRetrofit does not ship with any default way to make network requests. The\nsecond uses a serializer (Gson) to hook into Retrofit's Converter\nfunctionality. This allows for automatic serialization of request bodies\nand deserialization of response bodies.\n\n```php\ninterface GitHubService\n{\n    /**\n     * @GET(\"/users/{user}/list\")\n     * @Path(\"user\")\n     * @ResponseBody(\"App\\GithubService\\ListRepo\")\n     * @ErrorBody(\"App\\GitHubService\\ApiError\")\n     */\n    public function listRepos(string $user): Call;\n}\n```\n\nAnnotations are used to configure the endpoint.\nThen, the `Retrofit` class generates a working implementation of the\nservice interface.\n\n```php\n$retrofit = Retrofit::builder()\n    -\u003esetBaseUrl('https://api.github.com')\n    -\u003esetHttpClient(new Guzzle6HttpClient(new Client())) // requires a separate library\n    -\u003eaddConverterFactory(new GsonConverterFactory(Gson::builder()-\u003ebuild())) // requies a separate library\n    -\u003ebuild();\n    \n$gitHubService = $retrofit-\u003ecreate(GitHubService::class);\n```\n\nOur newly created service is capable of making GET requests to\n/users/{user}/list, which returns a `Call` object.\n\n```php\n$call = $gitHubService-\u003elistRepos('octocat');\n```\n\nThe `Call` object is then used to execute the request synchronously\nor asynchronously, returning a response.\n\n```php\n$response = $call-\u003eexecute();\n\n// or\n\n$call-\u003eenqueue(\n    function(Response $response) { }, // response callback (optional)\n    function(Throwable $throwable) { } // error callback (optional)\n);\n$call-\u003ewait();\n```\n\nYou can then check to see if the request was successful and get the\ndeserialized response body.\n\n```php\nif (!$response-\u003eisSuccessful()) {\n    throw new ApiException($response-\u003eerrorBody());\n}\n\n$responseBody = $response-\u003ebody();\n```\n\n*Usage examples are referenced from Square's documentation*\n\n\nInstallation \u0026 Usage\n--------------------\n\n*Retrofit 3 requires PHP 7.1*\n\n```bash\ncomposer require tebru/retrofit-php\n```\n\nPlease make sure you also install an http client.\n\n```bash\ncomposer require tebru/retrofit-php-http-guzzle6\n```\n\nInstall a converter to handle more advanced request and response body\nconversions.\n\n```bash\ncomposer require tebru/retrofit-php-converter-gson\n```\n\n### Documentation \n\n- [Installation](docs/installation.md)\n- [Getting Started](docs/usage.md)\n- [Advanced Usage](docs/advanced_usage.md)\n- [Annotation Reference](docs/annotations.md)\n\nLicense\n-------\n\nThis project is licensed under the MIT license. Please see the `LICENSE` file\nfor more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftebru%2Fretrofit-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftebru%2Fretrofit-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftebru%2Fretrofit-php/lists"}