PHPackages                             talentrydev/retrofit-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. talentrydev/retrofit-php

ActiveLibrary[API Development](/categories/api)

talentrydev/retrofit-php
========================

Retrofit for PHP - A type-safe PHP REST client.

v3.2.3(1y ago)01.2kMITPHPPHP &gt;= 7.1

Since Jun 12Pushed 1y agoCompare

[ Source](https://github.com/talentrydev/retrofit-php)[ Packagist](https://packagist.org/packages/talentrydev/retrofit-php)[ RSS](/packages/talentrydev-retrofit-php/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (8)Versions (3)Used By (0)

Retrofit PHP
============

[](#retrofit-php)

[![Build Status](https://camo.githubusercontent.com/dc4b0e6087a52036d8a43a6be2065b6a4d95d6033086d923f32327733bc9e213/68747470733a2f2f7472617669732d63692e6f72672f74656272752f726574726f6669742d7068702e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/tebru/retrofit-php)[![Code Coverage](https://camo.githubusercontent.com/9352f755a5188f625b83752d793cfde19ca6bbb9ad50954e237c82a2bae7df0b/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f74656272752f726574726f6669742d7068702f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/tebru/retrofit-php/?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/354924519b72d2da57aabbd7261e6ca111ff339590329849096ff01dbfa23b50/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f74656272752f726574726f6669742d7068702f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/tebru/retrofit-php/?branch=master)[![SensioLabsInsight](https://camo.githubusercontent.com/65c3ca3d9cf731774f757272db7ac16cf7d22807d32ba1297be5fcc1ed27acd7/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f64323138386266382d383234382d346466362d386263352d3831353066633062383839382f6d696e692e706e67)](https://insight.sensiolabs.com/projects/d2188bf8-8248-4df6-8bc5-8150fc0b8898)

Retrofit is a type-safe REST client. It is blatantly stolen from [square/retrofit](https://github.com/square/retrofit) and implemented in PHP.

❗UPGRADE NOTICE❗
----------------

[](#upgrade-notice)

**Version 3 introduces many breaking changes. Please review the [upgrade guide](docs/upgrade_2_3.md) before upgrading.**

Overview
--------

[](#overview)

*The following is for version 3, please check out the corresponding tag for version 2 documentation*

Retrofit allows you to define your REST API with a simple interface. The follow example will attempt to display a typical use-case, but requires two additional libraries. The first uses Guzzle to make http requests as Retrofit does not ship with any default way to make network requests. The second uses a serializer (Gson) to hook into Retrofit's Converter functionality. This allows for automatic serialization of request bodies and deserialization of response bodies.

```
interface GitHubService
{
    /**
     * @GET("/users/{user}/list")
     * @Path("user")
     * @ResponseBody("App\GithubService\ListRepo")
     * @ErrorBody("App\GitHubService\ApiError")
     */
    public function listRepos(string $user): Call;
}
```

Annotations are used to configure the endpoint. Then, the `Retrofit` class generates a working implementation of the service interface.

```
$retrofit = Retrofit::builder()
    ->setBaseUrl('https://api.github.com')
    ->setHttpClient(new Guzzle6HttpClient(new Client())) // requires a separate library
    ->addConverterFactory(new GsonConverterFactory(Gson::builder()->build())) // requies a separate library
    ->build();

$gitHubService = $retrofit->create(GitHubService::class);
```

Our newly created service is capable of making GET requests to /users/{user}/list, which returns a `Call` object.

```
$call = $gitHubService->listRepos('octocat');
```

The `Call` object is then used to execute the request synchronously or asynchronously, returning a response.

```
$response = $call->execute();

// or

$call->enqueue(
    function(Response $response) { }, // response callback (optional)
    function(Throwable $throwable) { } // error callback (optional)
);
$call->wait();
```

You can then check to see if the request was successful and get the deserialized response body.

```
if (!$response->isSuccessful()) {
    throw new ApiException($response->errorBody());
}

$responseBody = $response->body();
```

*Usage examples are referenced from Square's documentation*

Installation &amp; Usage
------------------------

[](#installation--usage)

*Retrofit 3 requires PHP 7.1*

```
composer require tebru/retrofit-php
```

Please make sure you also install an http client.

```
composer require tebru/retrofit-php-http-guzzle6
```

Install a converter to handle more advanced request and response body conversions.

```
composer require tebru/retrofit-php-converter-gson
```

### Documentation

[](#documentation)

- [Installation](docs/installation.md)
- [Getting Started](docs/usage.md)
- [Advanced Usage](docs/advanced_usage.md)
- [Annotation Reference](docs/annotations.md)

License
-------

[](#license)

This project is licensed under the MIT license. Please see the `LICENSE` file for more information.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance33

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 95.2% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~396 days

Total

2

Last Release

674d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/43603889?v=4)[talentrydev](/maintainers/talentrydev)[@talentrydev](https://github.com/talentrydev)

---

Top Contributors

[![natebrunette](https://avatars.githubusercontent.com/u/1831497?v=4)](https://github.com/natebrunette "natebrunette (260 commits)")[![Gounlaf](https://avatars.githubusercontent.com/u/236413?v=4)](https://github.com/Gounlaf "Gounlaf (6 commits)")[![jdreesen](https://avatars.githubusercontent.com/u/424602?v=4)](https://github.com/jdreesen "jdreesen (3 commits)")[![mattjanssen](https://avatars.githubusercontent.com/u/745319?v=4)](https://github.com/mattjanssen "mattjanssen (3 commits)")[![talentrydev](https://avatars.githubusercontent.com/u/43603889?v=4)](https://github.com/talentrydev "talentrydev (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/talentrydev-retrofit-php/health.svg)

```
[![Health](https://phpackages.com/badges/talentrydev-retrofit-php/health.svg)](https://phpackages.com/packages/talentrydev-retrofit-php)
```

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[silverstripe/framework

The SilverStripe framework

7213.5M2.5k](/packages/silverstripe-framework)[phpdocumentor/phpdocumentor

Documentation Generator for PHP

4.4k3.1M878](/packages/phpdocumentor-phpdocumentor)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.0k15.4k](/packages/prestashop-prestashop)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

595.2M386](/packages/shopware-core)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
