PHPackages                             nacosvel/feign - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. nacosvel/feign

ActiveLibrary[HTTP &amp; Networking](/categories/http)

nacosvel/feign
==============

Implementing a Feign HTTP Client in PHP.

1.x-dev(1y ago)04MITPHPPHP &gt;=8.0

Since Sep 22Pushed 1y ago1 watchersCompare

[ Source](https://github.com/nacosvel/feign)[ Packagist](https://packagist.org/packages/nacosvel/feign)[ RSS](/packages/nacosvel-feign/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (3)Versions (2)Used By (0)

Nacosvel Feign HTTP Client
==========================

[](#nacosvel-feign-http-client)

This is a PHP implementation inspired by the Feign client used in microservices architecture. It provides a lightweight HTTP client that integrates declarative web service calling with easy annotation-based APIs.

[![GitHub Tag](https://camo.githubusercontent.com/57a8358bced17d5a653c25ec50ae99cdcc02bba2fa3db5e0b2266680e95ad824/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f7461672f6e61636f7376656c2f666569676e)](https://github.com/nacosvel/feign/tags)[![Total Downloads](https://camo.githubusercontent.com/ea801a0488a77b6207373201abb922f200f4e7f3f53a008563f4ad88c2d3e3ca/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6e61636f7376656c2f666569676e3f7374796c653d666c61742d737175617265)](https://packagist.org/packages/nacosvel/feign)[![Packagist Version](https://camo.githubusercontent.com/0fcd32c6df7c2a0819f131d7110cfd6597c46a8d40e2e914cdcbc7bec2360a14/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6e61636f7376656c2f666569676e)](https://packagist.org/packages/nacosvel/feign)[![Packagist PHP Version Support](https://camo.githubusercontent.com/3b62c90b8684192a40c084e0b171f52ae93bf6e7be1398a170e5f5b9c1e8112a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6e61636f7376656c2f666569676e)](https://github.com/nacosvel/feign)[![Packagist License](https://camo.githubusercontent.com/1d7084d6d5ddab085ff364f70f0533a7af7bd7c610a9240f959c5f288f9e66fb/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6e61636f7376656c2f666569676e)](https://github.com/nacosvel/feign)

Features
--------

[](#features)

- Declarative HTTP client interface
- Annotation-driven request handling
- Custom middleware for requests and responses
- Extensible with various mapping and middleware interfaces
- Support for microservices with FeignClient annotations

Development Plan
----------------

[](#development-plan)

- Supports `#[EnableFeignClients]` annotation
- Supports `#[Autowired]` annotation
- Supports `#[FeignClient]` annotation
- Supports `#[RequestMapping]` annotation
- Supports `#[RequestAttribute]` annotation
- Supports `#[Middleware]` annotation
- Support custom response type
- Implement service discovery
- Support Without Interface Dependency

Installation
------------

[](#installation)

You can install the package via [Composer](https://getcomposer.org/):

```
composer require nacosvel/feign
```

Quick Start
-----------

[](#quick-start)

It is super easy to get started with your first project.

> Your project must support `PSR-11`.

### Step 1 : Build a [FeignRegistrar](src/FeignRegistrar.php) instance in the service provider of your project's container.

[](#step-1--build-a-feignregistrar-instance-in-the-service-provider-of-your-projects-container)

```
use Nacosvel\Feign\FeignRegistrar;

class AppServiceProvider extends ServiceProvider
{
    public function boot(): void
    {
        FeignRegistrar::builder();
    }

}
```

### Step 2 : Use [`#[Autowired]`](src/Annotation/Autowired.php) to inject properties.

[](#step-2--use-autowired-to-inject-properties)

```
use Nacosvel\Feign\Annotation\Autowired;
use Nacosvel\Feign\Contracts\AutowiredInterface;

class PostController implements AutowiredInterface
{
    #[Autowired]
    protected PostInterface|AutowiredInterface $post;

    public function index(): string
    {
        return $this->post->detail(name: 'nacosvel/feign', version: 'v1.0.0')->getRawContents();
    }

}
```

### Step 3 : Define interfaces using [`#[FeignClient]`](src/Annotation/FeignClient.php) and [`#[RequestMapping]`](src/Annotation/RequestMapping.php).

[](#step-3--define-interfaces-using-feignclient-and-requestmapping)

```
use Nacosvel\Feign\Annotation\FeignClient;
use Nacosvel\Feign\Annotation\RequestGetMapping;
use Nacosvel\Feign\Contracts\ServiceInterface;
use Nacosvel\Feign\Contracts\TransformationInterface;

#[FeignClient(name: 'debug', path: '/')]
interface PostInterface
{
    #[RequestGetMapping(path: '/get')]
    public function detail(string $name = '', string $version = ''): Post|ServiceInterface|TransformationInterface;

}
```

Advanced Usage
--------------

[](#advanced-usage)

### Step 1 : Construct a [FeignRegistrar](src/FeignRegistrar.php) instance and set a custom [Configuration](src/Configuration/Configuration.php) class.

[](#step-1--construct-a-feignregistrar-instance-and-set-a-custom-configuration-class)

```
use Nacosvel\Feign\Annotation\EnableFeignClients;
use Nacosvel\Feign\FeignConfiguration;
use Nacosvel\Feign\FeignRegistrar;

#[EnableFeignClients(FeignConfiguration::class)]
class AppServiceProvider extends ServiceProvider
{
    public function boot(): void
    {
        FeignRegistrar::builder($this->app);
    }

}
```

### Step 2 : Inject properties and add [Middleware](src/Annotation/Middleware.php).

[](#step-2--inject-properties-and-add-middleware)

```
use Nacosvel\Feign\Annotation\Autowired;
use Nacosvel\Feign\Annotation\Middleware;
use Nacosvel\Feign\Annotation\RequestMiddleware;
use Nacosvel\Feign\Annotation\ResponseMiddleware;
use Nacosvel\Feign\Contracts\AutowiredInterface;

class PostController implements AutowiredInterface
{
    #[Autowired]
    #[Middleware(Request::class, Response::class)]
    #[RequestMiddleware(Request::class)]
    #[ResponseMiddleware(Response::class)]
    protected PostInterface|AutowiredInterface $post;

    public function index(): string
    {
        return $this->post->detail(name: 'nacosvel/feign', version: 'v1.0.0')->getRawContents();
    }

}
```

### Step 3 : More configurations for defining interfaces.

[](#step-3--more-configurations-for-defining-interfaces)

```
use Nacosvel\Feign\Annotation\FeignClient;
use Nacosvel\Feign\Annotation\RequestAttribute;
use Nacosvel\Feign\Annotation\RequestGetMapping;
use Nacosvel\Feign\Annotation\Middleware;
use Nacosvel\Feign\Annotation\RequestMiddleware;
use Nacosvel\Feign\Annotation\ResponseMiddleware;
use Nacosvel\Feign\Configuration\Client;
use Nacosvel\Feign\Configuration\Configuration;
use Nacosvel\Feign\Configuration\Fallback;
use Nacosvel\Feign\Support\Service;

#[FeignClient(
    name: 'debug',
    url: 'https://httpbin.org/',
    path: '/',
    configuration: Configuration::class,
    fallback: Fallback::class,
    client: Client::class
)]
#[Middleware(Request::class, Response::class)]
#[RequestMiddleware(Request::class)]
#[ResponseMiddleware(Response::class)]
interface PostInterface
{
    #[RequestGetMapping(path: '/get?id={id}', params: 'id=123456')]
    #[RequestAttribute(value: RequestAttribute::QUERY)]
    #[Middleware(Request::class, Response::class)]
    #[RequestMiddleware(Request::class)]
    #[ResponseMiddleware(Response::class)]
    public function detail(string $name = '', string $version = ''): Post|Service;

}
```

- To add custom [Configuration](src/Configuration/Configuration.php), [Fallback](src/Configuration/Fallback.php), and [Client](src/Configuration/Client.php) settings for FeignClient;
- using [Middleware](src/Annotation/Middleware.php)
- and specify [request data attributes](src/Annotation/RequestAttribute.php)

Advanced Example
----------------

[](#advanced-example)

This implementation enhances Feign to support remote microservice calls without relying on defined interfaces. This feature allows for more flexible remote service invocation where you don't need to pre-define interfaces for each service.

```
use Nacosvel\Feign\Annotation\Autowired;
use Nacosvel\Feign\Annotation\RequestGetMapping;
use Nacosvel\Feign\Contracts\AutowiredInterface;
use Nacosvel\Feign\Contracts\ReflectiveInterface;

class PostController implements AutowiredInterface
{
    #[Autowired]
    #[FeignClient(name: 'debug', url: 'https://httpbin.org/', path: '/')]
    #[RequestGetMapping(path: '/uuid')]
    protected ReflectiveInterface $post;

    public function index(): string
    {
        return $this->post->uuid()->getRawContents();
    }

}
```

Documentation
-------------

[](#documentation)

### Configuration Reference

[](#configuration-reference)

```
public function getDefaultMethod(): string;
```

Get the default request method, which takes effect when not specified.

```
public function converters(): array;
```

Overriding this method can achieve custom response types.

```
public function getService(?string $name = null): string|array|null;
```

Randomly select a service from multiple service addresses.

### Fallback Reference

[](#fallback-reference)

```
public function __invoke(
        RequestInterface  $request,
        ResponseInterface $response,
        array             $options = [],
        Throwable         $previous = null
    ): ResponseInterface;
```

Exception responses can be uniformly handled here.

### Client Reference

[](#client-reference)

```
public function __invoke(): ClientInterface;
```

For a custom request instance, you need to return an instance of `GuzzleHttp\ClientInterface`.

License
-------

[](#license)

Nacosvel Feign is made available under the MIT License (MIT). Please see [License File](LICENSE) for more information.

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance36

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity30

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

595d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2da9b458375a1b7972b7c4d26a5bf8f3e48db305e8805da36f253956f33c5568?d=identicon)[jundayw](/maintainers/jundayw)

---

Top Contributors

[![jundayw](https://avatars.githubusercontent.com/u/16873970?v=4)](https://github.com/jundayw "jundayw (100 commits)")

### Embed Badge

![Health badge](/badges/nacosvel-feign/health.svg)

```
[![Health](https://phpackages.com/badges/nacosvel-feign/health.svg)](https://phpackages.com/packages/nacosvel-feign)
```

###  Alternatives

[friendsofsymfony/rest-bundle

This Bundle provides various tools to rapidly develop RESTful API's with Symfony

2.8k73.3M318](/packages/friendsofsymfony-rest-bundle)[php-http/discovery

Finds and installs PSR-7, PSR-17, PSR-18 and HTTPlug implementations

1.3k309.5M1.2k](/packages/php-http-discovery)[nyholm/psr7

A fast PHP7 implementation of PSR-7

1.3k235.4M2.4k](/packages/nyholm-psr7)[pusher/pusher-php-server

Library for interacting with the Pusher REST API

1.5k94.8M292](/packages/pusher-pusher-php-server)[spatie/crawler

Crawl all internal links found on a website

2.8k16.3M52](/packages/spatie-crawler)[react/http

Event-driven, streaming HTTP client and server implementation for ReactPHP

78126.4M414](/packages/react-http)

PHPackages © 2026

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