PHPackages                             johnpbloch/fluent-http-api - 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. johnpbloch/fluent-http-api

ActiveLibrary[API Development](/categories/api)

johnpbloch/fluent-http-api
==========================

A general purpose fluent API wrapper

v1.0.0(2y ago)113MITPHPPHP &gt;=8.0.0

Since Jul 13Pushed 2y ago1 watchersCompare

[ Source](https://github.com/johnpbloch/fluent-http-api)[ Packagist](https://packagist.org/packages/johnpbloch/fluent-http-api)[ RSS](/packages/johnpbloch-fluent-http-api/feed)WikiDiscussions master Synced 1mo ago

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

Fluent HTTP API Wrapper
=======================

[](#fluent-http-api-wrapper)

Use this library to quickly build wrappers for HTTP APIs

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

[](#installation)

Add this to your PHP project with composer:

```
composer require johnpbloch/fluent-http-api
```

Usage
-----

[](#usage)

### Customize Configuration

[](#customize-configuration)

**The following is only necessary if you are building a library meant for distribution!**

If you are incorporating this in a codebase meant to be used as a library (i.e. as a dependency in other projects), you should create your own extensions of the `\JohnPBloch\FluentApi\Config` and `\JohnPBloch\FluentApi\Endpoint` classes and ensure that initializing the configuration object for your library stores that configuration in your custom base endpoint:

```
// Custom Endpoint:

class MyEndpoint extends \JohnPBloch\FluentApi\Endpoint
{
    public static function setConfig(\JohnPBloch\FluentApi\Config $config): \JohnPBloch\FluentApi\Config
    {
        return self::$config = $config;
    }

    protected function getConfig() : \JohnPBloch\FluentApi\Config {
        return self::$config;
    }
}

// Custom Config

class MyConfig extends \JohnPBloch\FluentApi\Config
{
    protected function setConfigOnBaseEndpoint(): static
    {
        return MyEndpoint::setConfig($this);
    }
}
```

### Authorization

[](#authorization)

This package provides a number of methods of adding authorization to requests. ***NOTE:*** This library does not handle authentication, it assumes you already have credentials available to use. The following methods of authorization are available:

- [Basic Auth](#basic-auth)
- [Digest Auth](#digest-auth)
- [NTLM Auth](#ntlm-auth)
- [Bearer Token](#bearer-token-auth)
- [Header Key/Value](#header-keyvalue-auth)
- [Query Key/Value](#query-keyvalue-auth)
- [Cookie-based auth](#cookie-based-auth)

##### Basic Auth

[](#basic-auth)

```
use JohnPBloch\FluentApi\Auth\BasicAuth;
$auth = new BasicAuth('username', 'password');
```

##### Digest Auth

[](#digest-auth)

```
use JohnPBloch\FluentApi\Auth\DigestAuth;
$auth = new DigestAuth('username', 'password', 'digest');
```

##### NTLM Auth

[](#ntlm-auth)

```
use JohnPBloch\FluentApi\Auth\NtlmAuth;
$auth = new NtlmAuth('username', 'password', 'ntlm');
```

##### Bearer Token Auth

[](#bearer-token-auth)

Only include the token, not the `Bearer ` prefix.

```
use JohnPBloch\FluentApi\Auth\BearerAuth;
$auth = new BearerAuth('token');
```

##### Header Key/Value Auth

[](#header-keyvalue-auth)

```
use JohnPBloch\FluentApi\Auth\HeaderAuth;
$auth = new HeaderAuth('X-Header-Name', 'header value');
```

##### Query Key/Value Auth

[](#query-keyvalue-auth)

```
use JohnPBloch\FluentApi\Auth\QueryVariableAuth;
$auth = new QueryVariableAuth('query_var_name', 'token');
```

##### Cookie-based Auth

[](#cookie-based-auth)

```
use JohnPBloch\FluentApi\Auth\CookieAuth;
$auth = new CookieAuth('cookie-name', 'cookie-value', 'domain.com');
```

### Initialize Configuration

[](#initialize-configuration)

Before using this library, you will have to initialize the configuration object. If you extended the Config object for packaging in a library, use that config object instead of `\JohnPBloch\FluentApi\Config`.

```
use JohnPBloch\FluentApi\Config;

Config::initialize('https://api.some-domain.com/base-path/', $auth)
```

### Make Requests

[](#make-requests)

Use the `method()` method to set the HTTP request method (e.g. GET, POST, etc.)

Use the `path()` method to set the path relative to the configured base uri.

The `send()` method will send the request and return a PSR-7 compatible Guzzle response.

Additionally, the Endpoint class extends the Laravel `Fluent` class and can add generic data to the request using fluent methods. By default, `GET`, `POST`, and `PUT` will automatically add fluent attributes to the request. `GET` data will be added to the query variables; `POST` and `PUT` requests will set fluent attributes to body data as a `application/x-www-form-urlencoded` request. If you need to further adjust the request, you will need to extend Endpoint to further adjust the config data before sending.

For example, a simple GET request:

```
use JohnPBloch\FluentApi\Endpoint;

$response = Endpoint::make()
    ->method('GET')
    ->path('resource/path')
    ->send();
```

Or a Post Request:

```
use JohnPBloch\FluentApi\Endpoint;

$response = Endpoint::make()
    ->method('POST')
    ->path('article')
    ->title('This Article Will Change Your Life')
    ->content('Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque commodo lacus et justo dictum, in imperdiet metus sagittis. Integer vestibulum justo quis tortor venenatis, a tempus justo pulvinar. Duis feugiat id orci ac condimentum. Fusce pellentesque dapibus tempus. Nulla nisi turpis, luctus sit amet enim sed, vulputate malesuada erat. Quisque varius quam eget sapien lobortis, ut vulputate nisl elementum. Proin sollicitudin eu ipsum vel mattis.')
    ->send();
```

#### Overriding Configuration Settings

[](#overriding-configuration-settings)

If there is a specific configuration option you need to override, you can extend the Endpoint class and set public or protected methods to override values. There are two types of override methods: `setRequestConfig*` and `mergeRequestConfig*`. For each one, the remaining text after `Config` will determine the configuration key that will be set. The text will be snake-cased before using. So for example, a method named `setRequestConfigFormParams()` will set the return value to `form_params` in Guzzle options.

`setRequestConfig*` methods will get the current Guzzle option as the only parameter and whatever the method returns will get set to the Guzzle options.

`mergeRequestConfig*` methods will merge the return value into the existing (possibly empty) value in the Guzzle options. There is no input for these methods.

Before sending the Guzzle request, the Endpoint will call `beforeSend($options)`. `beforeSend` can return either an options array or a `\Psr\Http\Message\ResponseInterface` object. If it returns an options array, the request will send as expected. If it returns a response object, it will be returned as-is without sending the request or running the `afterSend` method.

After sending the Guzzle request, the response object will call `afterSend()` with the response. `afterSend()` must return a response as well, and that response will be returned by `send()`.

License
-------

[](#license)

Licensed under MIT license.

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 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

1032d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/044e10bd302ddb296511f2a463f61314bc17338c34fc0d292d05a425c655bc34?d=identicon)[johnpbloch](/maintainers/johnpbloch)

---

Top Contributors

[![johnpbloch](https://avatars.githubusercontent.com/u/446833?v=4)](https://github.com/johnpbloch "johnpbloch (29 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/johnpbloch-fluent-http-api/health.svg)

```
[![Health](https://phpackages.com/badges/johnpbloch-fluent-http-api/health.svg)](https://phpackages.com/packages/johnpbloch-fluent-http-api)
```

###  Alternatives

[skagarwal/google-places-api

Google Places Api

1913.0M8](/packages/skagarwal-google-places-api)[dcblogdev/laravel-microsoft-graph

A Laravel Microsoft Graph API (Office365) package

168285.5k1](/packages/dcblogdev-laravel-microsoft-graph)[vluzrmos/slack-api

Wrapper for Slack.com WEB API.

102589.1k3](/packages/vluzrmos-slack-api)[smodav/mpesa

M-Pesa API implementation

16363.7k1](/packages/smodav-mpesa)[jasara/php-amzn-selling-partner-api

A fluent interface for Amazon's Selling Partner API in PHP

1344.8k1](/packages/jasara-php-amzn-selling-partner-api)[grantholle/powerschool-api

A Laravel package to make interacting with PowerSchool less painful.

1715.6k1](/packages/grantholle-powerschool-api)

PHPackages © 2026

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