PHPackages                             friendsofapi/boilerplate - 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. friendsofapi/boilerplate

ActiveLibrary[API Development](/categories/api)

friendsofapi/boilerplate
========================

A good base for a API client

18102[5 issues](https://github.com/FriendsOfApi/boilerplate/issues)PHP

Since May 21Pushed 8y ago3 watchersCompare

[ Source](https://github.com/FriendsOfApi/boilerplate)[ Packagist](https://packagist.org/packages/friendsofapi/boilerplate)[ RSS](/packages/friendsofapi-boilerplate/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

FriendsOfApi Boilerplate
========================

[](#friendsofapi-boilerplate)

[![Latest Version](https://camo.githubusercontent.com/88710104b32c4ce45ac890b64cb03365d9103565d32de1dd9a4e47ad40bfb2aa/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f467269656e64734f664170692f626f696c6572706c6174652e7376673f7374796c653d666c61742d737175617265)](https://github.com/FriendsOfApi/boilerplate/releases)[![Build Status](https://camo.githubusercontent.com/f1fea7aae6926f71ae6431434897edaff36cd80ebc4429554348f7d8387166d6/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f467269656e64734f664170692f626f696c6572706c6174652e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/FriendsOfApi/boilerplate)[![Code Coverage](https://camo.githubusercontent.com/8b552a60f8ba9cfe66c6828b11c7ade6a43e5a424eb6651442e7f361909ff8b2/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f467269656e64734f664170692f626f696c6572706c6174652e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/FriendsOfApi/boilerplate)[![Quality Score](https://camo.githubusercontent.com/d65e854203815e51165af4e81d87a787598cde4e59f2b5adb9796abba3b2d596/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f467269656e64734f664170692f626f696c6572706c6174652e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/FriendsOfApi/boilerplate)[![Total Downloads](https://camo.githubusercontent.com/ebdea6194a5b30ecbb49180c1957871ba666badb214f32d9b9714e869df98747/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f667269656e64736f666170692f626f696c6572706c6174652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/friendsofapi/boilerplate)

Install
-------

[](#install)

Via Composer

```
$ composer require friendsofapi/boilerplate
```

Usage
-----

[](#usage)

```
$apiClient = new ApiClient();
$total = $apiClient->stats()->total();
echo $total->getCount(); // 22;
```

Example
-------

[](#example)

This repository contains an example API client for FakeTwitter. The API for FakeTwitter has the following endpoints.

MethodURIParametersGET/v1/tweets(string) hashtagPOST/v1/tweets/new(string) message, (string) location, (array) hashtagsGET/v1/tweets/{id}PUT/v1/tweets/{id}/edit(string) message, (string) location, (array) hashtagsDELETE/v1/tweets/{id}/deleteGET/v1/stats/{username}(int) start, (int) endGET/v1/stats/total(int) start, (int) endDevelop
-------

[](#develop)

APIs are usually split into categories, called **Resources**. In your implementation you should also reflect these categories, for example by having their own classes in `Api/`. Let's take a look at `Api/Stats` in our case. The response of any call should be an object in `Model/Stats/X`, like `Model/Stats/Total`.

### Hydrator

[](#hydrator)

The end user chooses which hydrator to use. The default one should return domain objects.

### Request builder

[](#request-builder)

The request builder creates a PSR-7 request with a multipart stream when necessary If the API does not require multipart streams you should remove the `RequestBuilder`and replace it with a `RequestFactory`.

### Domain objects as parameters

[](#domain-objects-as-parameters)

If the API requires lots of parameters for a specific endpoint it could be tempting to create a domain object and pass it as an argument to that endpoint.

```
public function create(string $username, Tweet $model) {
    // send the Tweet to Fake Twitter API
    // ...
}

$model = new Tweet();
$model->setMessage('foobar');
$model->addHashTag('stuff');
$model->addHashTag('test');
$model->setLocation('Stockhom/Sweden');
// ...
$api->create('foobar', $model);
```

This approach, however, is not preferred as the created Tweet object is an unnecessary overhead. It could also conflict with the application developers' Tweet object. Also, requests usually don't have the same parameters as responses, so using the same object for both is impossible in most of the cases. Instead of forcing the users to use your Tweet object you should use an array for passing parameters to the request.

```
public function create(string $username, array $param) {
    // send the Tweet to Fake Twitter API
    // ...
}

$param['message' => 'foobar'];
$param['hashtags' => ['stuff', 'test']];
$param['location' => 'Stockhom/Sweden'];
// ...
$api->create('foobar', $param);
```

If your parameters are complex, you can provide a TweetBuilder. Since it's a builder, fluent interface might be a good idea here. But be aware that [fluent interfaces are evil](https://ocramius.github.io/blog/fluent-interfaces-are-evil/).

```
public function create(string $username, array $param) {
    // send the Tweet to Fake Twitter API
    // ...
}

$builder = (new TweetBuilder())
    ->setMessage('foobar');
    ->addHashTag('stuff');
    ->addHashTag('test');
    ->setLocation('Stockhom/Sweden')
;

// ...
$api->create('foobar', $builder->build());
```

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance14

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

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

### Community

Maintainers

![](https://www.gravatar.com/avatar/401ccc5eea13c60cf807ae982af00e368e2166e2f26d8eb541dcd881a57385bc?d=identicon)[Nyholm](/maintainers/Nyholm)

![](https://www.gravatar.com/avatar/0e4e105cea62b616d4cb376b08a849b6a428f646998537de150d16a8eb537b90?d=identicon)[mark.sagikazar](/maintainers/mark.sagikazar)

---

Top Contributors

[![Nyholm](https://avatars.githubusercontent.com/u/1275206?v=4)](https://github.com/Nyholm "Nyholm (30 commits)")[![sagikazarmark](https://avatars.githubusercontent.com/u/1226384?v=4)](https://github.com/sagikazarmark "sagikazarmark (22 commits)")

### Embed Badge

![Health badge](/badges/friendsofapi-boilerplate/health.svg)

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

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M480](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M272](/packages/twilio-sdk)[knplabs/github-api

GitHub API v3 client

2.2k15.8M187](/packages/knplabs-github-api)[facebook/php-business-sdk

PHP SDK for Facebook Business

90121.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

73813.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

263103.1M454](/packages/google-gax)

PHPackages © 2026

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