retrofit-php 0,0 travis-ci Packagist phpunit

Retrofit implementation in PHP. A REST client for PHP.

3 years after

Retrofit PHP

Build Status Coverage Status Scrutinizer Code Quality SensioLabsInsight

This library aims to ease creation of REST clients. It is blatantly stolen from square/retrofit and implemented in PHP.

Overview

Retrofit allows you to define your REST API with a simple interface.

<?php

use Tebru\Retrofit\Annotation as Rest;

interface GitHubService
{
    /**
     * @Rest\GET("/users/{user}/list")
     * @Rest\Returns("ArrayCollection<ListRepo>")
     */
    public function listRepos($user);
}

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

<?php

use Tebru\Retrofit\Adapter\RestAdapter;

$restAdapter = RestAdapter::builder()
    ->setBaseUrl('https://api.github.com')
    ->build();

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

Our newly created service is capable of making GET requests to /users/$user/list to return an ArrayCollection of ListRepo objects.

$repos = $gitHubService->listRepos('octocat');

Usage examples are referenced from Square's documentation

Installation & Usage

composer require tebru/retrofit-php

Please make sure you also install an http client. Currently guzzle is the only supported option

composer require guzzlehttp/guzzle

Documentation

License

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

Related Repositories

awesome-php

awesome-php

A curated list of amazingly awesome PHP libraries, resources and shiny things. ...

GracefulMovies

GracefulMovies

简影讯,简约精彩影讯。基于Retrofit+RxJava+MVP+Colorful多彩主题框架开发的高颜值影讯app。简约,优雅,精彩,即看即走,现已正式发布上 ...

GithubApp

GithubApp

A Github Client App with MVP architecture use Dagger2, RxJava, Retrofit, Okhttp ...

awesome-php-zh_CN

awesome-php-zh_CN

一个PHP资源列表,内容包括:库、框架、模板、安全、代码分析、日志、第三方库、配置工具、Web 工具、书籍、电子书、经典博文等等 ...

Elephant

Elephant

Elephant is PHPHub Community Android unofficial client, base on Material Design ...


Top Contributors

natebrunette mloberg tonynelson19 MaxVandervelde epfremmer

Dependencies

package version
php >= 5.4
jms/serializer ^1.0
phpoption/phpoption ^1.1
symfony/console ^2.3|^3.0
tebru/assert ^0.2
tebru/dynamo ^0.3.1
tebru/retrofit-http-clients ^0.6.6
symfony/event-dispatcher ^2.3|^3.0
guzzlehttp/psr7 ^1.0
psr/log ^1.0
dev mockery/mockery ^0.9.4
phpunit/phpunit ^4.0
guzzlehttp/guzzle ^5.3|^6.0
behat/behat ^3.1
tebru/retrofit-test-api ~0.1

Releases

-   v2.8.3 zip tar
-   v2.8.2 zip tar
-   v2.8.1 zip tar
-   v2.8.0 zip tar
-   v2.8.0-rc4 zip tar
-   v2.8.0-rc3 zip tar
-   v2.8.0-rc2 zip tar
-   v2.8.0-rc1 zip tar
-   v2.7.0 zip tar
-   v2.6.1 zip tar
-   v2.6.0 zip tar
-   v2.5.5 zip tar
-   v2.5.4 zip tar
-   v2.5.3 zip tar
-   v2.5.2 zip tar
-   v2.5.1 zip tar
-   v2.5.0 zip tar
-   v2.4.0 zip tar
-   v2.3.0 zip tar
-   v2.2.0 zip tar
-   v2.1.0 zip tar
-   v2.0.6 zip tar
-   v2.0.5 zip tar
-   v2.0.4 zip tar
-   v2.0.3 zip tar
-   v2.0.2 zip tar
-   v2.0.1 zip tar
-   v2.0.0 zip tar
-   v1.2.1 zip tar
-   v1.2.0 zip tar