{"id":36975313,"url":"https://github.com/mehdilight/retrofit-php","last_synced_at":"2026-01-13T22:04:21.276Z","repository":{"id":325950590,"uuid":"1101342713","full_name":"mehdilight/retrofit-php","owner":"mehdilight","description":"A type-safe HTTP client for PHP, inspired by Square's Retrofit for Java/Kotlin.","archived":false,"fork":false,"pushed_at":"2025-11-24T11:36:55.000Z","size":139,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-11-28T01:10:02.517Z","etag":null,"topics":["api","async","client","guzzle","http","rest","retrofit","streaming","type-safe"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mehdilight.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":"roadmap.md","authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-11-21T14:40:01.000Z","updated_at":"2025-11-25T10:25:00.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/mehdilight/retrofit-php","commit_stats":null,"previous_names":["mehdilight/retrofit-php"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/mehdilight/retrofit-php","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mehdilight%2Fretrofit-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mehdilight%2Fretrofit-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mehdilight%2Fretrofit-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mehdilight%2Fretrofit-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mehdilight","download_url":"https://codeload.github.com/mehdilight/retrofit-php/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mehdilight%2Fretrofit-php/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28400848,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-13T14:36:09.778Z","status":"ssl_error","status_checked_at":"2026-01-13T14:35:19.697Z","response_time":56,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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","async","client","guzzle","http","rest","retrofit","streaming","type-safe"],"created_at":"2026-01-13T22:04:21.211Z","updated_at":"2026-01-13T22:04:21.271Z","avatar_url":"https://github.com/mehdilight.png","language":"PHP","funding_links":["https://buymeacoffee.com/phpmystic"],"categories":[],"sub_categories":[],"readme":"# Retrofit PHP\n\nA type-safe HTTP client for PHP, inspired by [Square's Retrofit](https://square.github.io/retrofit/) for Java/Kotlin.\n\nTurn your HTTP API into a PHP interface using attributes.\n\n## Features\n\n- ✅ **Type-Safe API Definitions** - Define APIs as PHP interfaces with attributes\n- ✅ **HTTP Methods** - Support for GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS\n- ✅ **URL Parameters** - Path parameters, query parameters, and query maps\n- ✅ **Request Body** - JSON, form-encoded, and multipart requests\n- ✅ **Headers** - Static and dynamic headers\n- ✅ **Converters** - JSON, XML, and custom converters\n- ✅ **DTO Hydration** - Automatic object mapping with nested objects and field name mapping\n- ✅ **Async Requests** - Promise-based async operations with Guzzle\n- ✅ **Retry Policies** - Automatic retries with exponential backoff\n- ✅ **Response Caching** - TTL-based caching with pluggable cache backends\n- ✅ **Interceptors** - Request/response modification and logging\n- ✅ **Timeouts** - Per-endpoint timeout configuration\n- ✅ **File Handling** - Streaming uploads/downloads with progress tracking\n- ✅ **PSR-7 \u0026 PSR-18 Compliant** - Full PSR standards support\n- ✅ **XML Support** - Built-in XML serialization/deserialization\n- ✅ **Symfony Serializer** - Advanced serialization with groups and contexts\n\n## Installation\n\n```bash\ncomposer require phpmystic/retrofit-php\n```\n\n## Quick Start\n\n### 1. Define your API interface\n\n```php\nuse Phpmystic\\RetrofitPhp\\Attributes\\Http\\GET;\nuse Phpmystic\\RetrofitPhp\\Attributes\\Http\\POST;\nuse Phpmystic\\RetrofitPhp\\Attributes\\Parameter\\Path;\nuse Phpmystic\\RetrofitPhp\\Attributes\\Parameter\\Query;\nuse Phpmystic\\RetrofitPhp\\Attributes\\Parameter\\Body;\n\ninterface GitHubApi\n{\n    #[GET('/users/{user}')]\n    public function getUser(#[Path('user')] string $username): array;\n\n    #[GET('/users/{user}/repos')]\n    public function listRepos(\n        #[Path('user')] string $username,\n        #[Query('per_page')] int $perPage = 10,\n        #[Query('sort')] string $sort = 'updated'\n    ): array;\n\n    #[POST('/repos/{owner}/{repo}/issues')]\n    public function createIssue(\n        #[Path('owner')] string $owner,\n        #[Path('repo')] string $repo,\n        #[Body] array $issue\n    ): array;\n}\n```\n\n### 2. Create a Retrofit instance\n\n```php\nuse Phpmystic\\RetrofitPhp\\Retrofit;\nuse Phpmystic\\RetrofitPhp\\Http\\GuzzleHttpClient;\nuse Phpmystic\\RetrofitPhp\\Converter\\JsonConverterFactory;\n\n$retrofit = Retrofit::builder()\n    -\u003ebaseUrl('https://api.github.com')\n    -\u003eclient(GuzzleHttpClient::create(['timeout' =\u003e 30]))\n    -\u003eaddConverterFactory(new JsonConverterFactory())\n    -\u003ebuild();\n\n// Or use TypedJsonConverterFactory for automatic DTO hydration\nuse Phpmystic\\RetrofitPhp\\Converter\\TypedJsonConverterFactory;\n\n$retrofit = Retrofit::builder()\n    -\u003ebaseUrl('https://api.github.com')\n    -\u003eclient(GuzzleHttpClient::create(['timeout' =\u003e 30]))\n    -\u003eaddConverterFactory(new TypedJsonConverterFactory())  // Enables DTO hydration\n    -\u003ebuild();\n```\n\n### 3. Use your API\n\n```php\n$github = $retrofit-\u003ecreate(GitHubApi::class);\n\n// GET request with path parameter\n$user = $github-\u003egetUser('octocat');\necho $user['name']; // \"The Octocat\"\n\n// GET request with query parameters\n$repos = $github-\u003elistRepos('octocat', perPage: 5, sort: 'stars');\n\n// POST request with body\n$issue = $github-\u003ecreateIssue('owner', 'repo', [\n    'title' =\u003e 'Bug report',\n    'body' =\u003e 'Something is broken',\n]);\n```\n\n## Documentation\n\n### Core Concepts\n- [HTTP Methods](docs/http-methods.md) - GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS\n- [URL Parameters](docs/parameters.md) - Path parameters, query parameters, and query maps\n- [Request Body](docs/request-body.md) - JSON, form-encoded, and multipart requests\n- [Headers](docs/headers.md) - Static and dynamic header configuration\n\n### Configuration\n- [HTTP Client Configuration](docs/client-configuration.md) - Guzzle options and custom clients\n- [Converters](docs/converters.md) - JSON, XML, Symfony Serializer, DTO hydration, and custom converters\n- [Timeouts](docs/timeouts.md) - Per-endpoint timeout configuration\n\n### Advanced Features\n- [Async Requests](docs/async.md) - Promise-based async operations and parallel requests\n- [Retry Policies](docs/retry.md) - Automatic retries with backoff strategies\n- [Response Caching](docs/caching.md) - TTL-based caching with custom backends\n- [Interceptors](docs/interceptors.md) - Request/response modification and logging\n- [File Handling](docs/file-handling.md) - Streaming uploads/downloads with progress tracking\n\n### Examples\n- [Complete Examples](docs/examples.md) - Full working examples with all features\n\n## Requirements\n\n- PHP 8.1+\n- Guzzle 7.0+\n\n**Optional Dependencies:**\n- PSR-18 HTTP Client: `psr/http-client` and a PSR-18 implementation (e.g., `symfony/http-client`, `nyholm/psr7`)\n- XML Support: Built-in (uses PHP's SimpleXML)\n- Symfony Serializer: `symfony/serializer` ^6.0 or ^7.0\n\n## Support\n\nIf you find this project helpful, consider supporting its development!\n\n\u003ca href=\"https://buymeacoffee.com/phpmystic\" target=\"_blank\"\u003e\n  \u003cimg src=\"https://media4.giphy.com/media/v1.Y2lkPTc5MGI3NjExZmdnOWMxcm5oNDUwbjdnbm83bDNncjB3czU3NzBvdHFzbWExZjN5dyZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9cw/7kZE0z52Sd9zSESzDA/giphy.gif\" alt=\"Buy Me A Coffee\" height=\"60\"\u003e\n\u003c/a\u003e\n\n[![Buy Me A Coffee](https://img.shields.io/badge/Buy%20Me%20A%20Coffee-support-yellow.svg?style=flat\u0026logo=buy-me-a-coffee)](https://buymeacoffee.com/phpmystic)\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmehdilight%2Fretrofit-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmehdilight%2Fretrofit-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmehdilight%2Fretrofit-php/lists"}