PHPackages                             piggly/php-api-client - 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. piggly/php-api-client

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

piggly/php-api-client
=====================

A client starter-kit used to interact with any REST API.

2.2.0(2y ago)69561[2 issues](https://github.com/piggly-dev/php-api-client/issues)MITPHPPHP &gt;=7.2

Since May 17Pushed 2y ago1 watchersCompare

[ Source](https://github.com/piggly-dev/php-api-client)[ Packagist](https://packagist.org/packages/piggly/php-api-client)[ Docs](https://github.com/piggly-dev/php-api-client)[ RSS](/packages/piggly-php-api-client/feed)WikiDiscussions develop Synced today

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

Api Client Starter-Kit
======================

[](#api-client-starter-kit)

[![Latest Version on Packagist](https://camo.githubusercontent.com/c39cccce6100103f1185d6da10b350add8e54dff359ec1e351427011e7c5724e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f706967676c792f7068702d6170692d636c69656e742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/piggly/php-api-client) [![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)

This open-source library is provided for cases where you need to do APIs calls with large flexibility that officials SDK may not provide out-of-the-box. When using this Starter-Kit, you will be able to make better cURL requests with a smart managing of requests and responses.

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

[](#installation)

### Composer

[](#composer)

1. At you console, in your project folder, type `composer require piggly/php-api-client`;
2. Don't forget to add Composer's autoload file at your code base `require_once('vendor/autoload.php);`.

### Manual install

[](#manual-install)

1. Download or clone with repository with `git clone https://github.com/piggly-dev/php-api-client.git`;
2. After, goes to `cd /path/to/piggly/php-api-client`;
3. Install all Composer's dependencies with `composer install`;
4. Add project's autoload file at your code base `require_once('/path/to/piggly/php-api-client/vendor/autoload.php);`.

Dependencies
------------

[](#dependencies)

The library has the following external dependencies:

- [PHP cURL extension](https://www.php.net/manual/en/intro.curl.php);
- [PHP JSON extension](https://php.net/manual/en/book.json.php);
- PHP 7.2+.

How to?
-------

[](#how-to)

### Configuration

[](#configuration)

This library provides, first, a `Configuration` object. You must create it before send any request. You may create many `Configuration` objects to provide different environments or you could use `.env` files to manages it.

See below all configurations:

ConfigurationMethodDescriptionApi Keys`apiKey()` and `getApiKey()`Add a new api key. You may have many.Access Token`accessToken()` and `getAccessToken()`Add an access token.Client Username`username()` and `getUsername()`HTTP Client Username to Basic Authentication.Client Password`password()` and `getPassword()`HTTP Client Secret to Basic Authentication.HTTP Headers`headers()` and `cloneHeaders()`Manage the defaults HTTP Headers.Host`host()` and `getHost()`Host URL to send Requests, without paths.UserAgent`userAgent()` and `getUserAgent()`UserAgent which is making Requestes.Timeout`timeout()` and `getTimeout()`The maximum number of seconds to allow cURL functions to execute.Connection Timeout`connectionTimeout()` and `getConnectionTimeout()`The maximum amount of time in seconds that is allowed to make the connection to the serverProxy Host`proxyHost()` and `getProxyHost()`Host for proxying.Proxy Port`proxyPort()` and `getProxyPort()`Port for proxying.Proxy Type`proxyType()` and `getProxyType()`cURL proxy type, e.g. CURLPROXY\_HTTP or CURLPROXY\_SOCKS5.Proxy User`proxyUser()` and `getProxyUser()`User for proxying.Proxy Password`proxyPassword()` and `getProxyPassword()`Password for proxying.Custom Configuration`custom()` and `getCustom()`Add any custom configuration.SSL Validation`verifySSL()` and `shouldVerifySSL()`If should or not do a SSL verification.Default Configuration`default` and `getDefault()`A static default configuration objects. It will be available to all Configuration instances.Development configurations:

With `debug()` method you will be able to enable requests debugging. You also may set a `Logger` to log messages across code lifetime. The `logger()` method is expecting a `Logger` from `monolog/monolog` package. Only when a `Logger` is set the `log()` method will output messages into `Logger`.

> **NOTE**: Debug messages will only be output to `Logger` when `debug()` mode is active.

### Requests

[](#requests)

After configuration is done, you are ready to use `Request` object. You may set a `Configuration` object to `Request` constructor or it will get the default configuration.

Then, you must start with request's methods: `delete()`, `head()`, `get()`, `options()`, `patch()`,`post()` and `put()`. After you will be able to manipulate request with methods below:

MethodDescription`basicAuth()`Apply basic authorization header.`authorization()`Apply authorization header with an api key.`getHeaders()`Manages all request headers.`headers()`Applies headers to request headers.`data()`Set the post data.`params()`Set parameters replaces to URI. At URI, `/posts/{id}` you may set `params(['id', 1])`, then it will be replaced `/posts/1`.`query()`Set query string parameters.`responseType()`Set the response type as `\SplFileObject`, `string` or `array`.When your request is done, you need to use `call()` method. The `call()` method will:

- Throw an `ApiRequestException`, if response fails;
- Throw an `ApiResponseException`, if response has a non 2xx response;
- Return a `Response` object with all response data and request reference.

#### Headers

[](#headers)

To manage headers, there is a `HeaderBag` object that will have all needed methods to better handle with headers.

Samples
-------

[](#samples)

You can see very lightweight samples at **/samples** folder.

Changelog
---------

[](#changelog)

See the [CHANGELOG](CHANGELOG.md) file for information about all code changes.

Testing the code
----------------

[](#testing-the-code)

This library uses the PHPUnit. We carry out tests of all the main classes of this application.

```
vendor/bin/phpunit
```

> You must always run tests with PHP 7.2 and greater.

Contributions
-------------

[](#contributions)

See the [CONTRIBUTING](CONTRIBUTING.md) file for information before submitting your contribution.

Credits
-------

[](#credits)

- [Caique Araujo](https://github.com/caiquearaujo)
- [All contributors](../../contributors)

Support the project
-------------------

[](#support-the-project)

Piggly Studio is an agency located in Rio de Janeiro, Brazil. If you like this library and want to support this job, be free to donate any value to BTC wallet `3DNssbspq7dURaVQH6yBoYwW3PhsNs8dnK` ❤.

License
-------

[](#license)

MIT License (MIT). See [LICENSE](LICENSE).

###  Health Score

28

—

LowBetter than 57% of packages

Maintenance13

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity57

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

Every ~41 days

Recently: every ~30 days

Total

20

Last Release

993d ago

Major Versions

1.2.0 → 2.0.02023-03-04

PHP version history (2 changes)1.0.0PHP ^7.2 || ^8.0

2.0.0PHP &gt;=7.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/8e37ceaff3cd04951d33004f062082f01b41c9b2adf5b2c241429bbf12362a5b?d=identicon)[piggly](/maintainers/piggly)

---

Top Contributors

[![caiquearaujo](https://avatars.githubusercontent.com/u/23598990?v=4)](https://github.com/caiquearaujo "caiquearaujo (64 commits)")

---

Tags

apiclientcurlRESTful APIpiggly

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/piggly-php-api-client/health.svg)

```
[![Health](https://phpackages.com/badges/piggly-php-api-client/health.svg)](https://phpackages.com/packages/piggly-php-api-client)
```

###  Alternatives

[tcdent/php-restclient

A generic REST API client for PHP

3552.9M22](/packages/tcdent-php-restclient)[aplus/http-client

Aplus Framework HTTP Client Library

2141.6M1](/packages/aplus-http-client)[vinelab/http

An http library developed for the laravel framework. aliases itself as HttpClient

57299.6k10](/packages/vinelab-http)[serpapi/google-search-results-php

Get Google, Bing, Baidu, Ebay, Yahoo, Yandex, Home depot, Naver, Apple, Duckduckgo, Youtube search results via SerpApi.com

69110.0k](/packages/serpapi-google-search-results-php)[ismaeltoe/osms

PHP library wrapper of the Orange SMS API.

4639.8k](/packages/ismaeltoe-osms)

PHPackages © 2026

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