PHPackages                             palanik/wrapi - 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. palanik/wrapi

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

palanik/wrapi
=============

Wrapper for calling Restful API

v0.1.7(8y ago)5315.6k↓18.9%14MITPHPPHP &gt;=5.5.0

Since Nov 20Pushed 8y ago1 watchersCompare

[ Source](https://github.com/palanik/wrapi-php)[ Packagist](https://packagist.org/packages/palanik/wrapi)[ Docs](https://github.com/palanik/wrapi-php)[ RSS](/packages/palanik-wrapi/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (4)Versions (8)Used By (4)

wrapi
=====

[](#wrapi)

Wrapper for calling Restful API

*`wrapi`* allows you to call HTTP based APIs just like making calls to ordinary php functions.

[![Latest Stable Version](https://camo.githubusercontent.com/e859cc6f03e57b6ddc8a82e90afe2c2b76e8a11027d4769ca8d39bf148901959/68747470733a2f2f706f7365722e707567782e6f72672f70616c616e696b2f77726170692f762f737461626c652e737667)](https://packagist.org/packages/palanik/wrapi)[![Build Status](https://camo.githubusercontent.com/d626219c442f541ec6117d20fd050ac4324e74ac0632044365cbf885a76606bd/68747470733a2f2f7472617669732d63692e6f72672f70616c616e696b2f77726170692d7068702e737667)](https://travis-ci.org/palanik/wrapi-php)[![License](https://camo.githubusercontent.com/d986437b02cffd4886b5a345db3230f60a7774a8dc4c831b0b888c011dd18f9f/68747470733a2f2f706f7365722e707567782e6f72672f70616c616e696b2f77726170692f6c6963656e73652e737667)](https://github.com/palanik/wrapi-php/blob/master/LICENSE)

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

[](#installation)

#### Install with [Composer](https://packagist.org/packages/palanik/wrapi)

[](#install-with-composer)

1. Update your `composer.json` to require `palanik/wrapi` package.
2. Run `composer install` to add wrapi your vendor folder.

```
{
  "require": {
    "palanik/wrapi": "*"
  }
}
```

or simply run

```
composer require palanik/wrapi
```

Easy Start
----------

[](#easy-start)

### Approach `I`

[](#approach-i)

1. Create an [array](#endpoints-array) listing all the API endpoints you want to work with.
2. [Wrap](#wrap-endpoints) endpoints with *`wrapi`*.
3. Call individual endpoints as [functions](#make-the-call).

See [Example Code](examples/github/example1.php)

### Approach `II`

[](#approach-ii)

1. Create [client object](#client-object) with API Base URL.
2. [Register](#register) API endpoints.
3. Call individual endpoints as [functions](#make-the-call).

See [Example Code](examples/github/example2.php)

---

### Endpoints Array

[](#endpoints-array)

Declare each endpoint as per the following specifications.

```
"function_name" => array(
	"method" => "HTTP_METHOD",					// 'GET', 'POST', 'PUT', 'PATCH' or 'DELETE'
	"path" => "relative/path/to/:api/endpoint"	// Can use `Slim`/`express` style path params
)
```

eg. a small set of github.com API

```
array(
	"repo" => array(
		"method" => "GET",
		"path" => "repos/:owner/:repo"
	),

	"contributors" => array(
		"method" => "GET",
		"path" => "repos/:owner/:repo/contributors"
	),

	"languages" => array(
		"method" => "GET",
		"path" => "repos/:owner/:repo/languages"
	),

	"tags" => array(
		"method" => "GET",
		"path" => "repos/:owner/:repo/tags"
	),

	"branches" => array(
		"method" => "GET",
		"path" => "repos/:owner/:repo/branches"
	)
)
```

### Wrap endpoints

[](#wrap-endpoints)

Create a API client object from *`wrapi`*. Provide the base url for the API and the endpoints array. *`wrapi`* will create a client object with all the necessary functions.

```
$endpoints = array(...);

$client = new wrapi\wrapi('https://api.github.com/',	// base url for the API
  endpoints 										// your endpoints array
);

// client object contains functions to call the API
```

### Register

[](#register)

Register additional API endpoints with the client object with a function name.

```
$client("zen",
	array(
		"method" => "GET",
		"path" => "zen"
		)
	);
```

### Make the call

[](#make-the-call)

Call the functions with arguments.

```
// This will make GET request to 'https://api.github.com/repos/guzzle/guzzle/contributors'
$contributors = $client->contributors('guzzle', 'guzzle');

$zenQuote = $client->zen();
echo "Today's quote: ". $zenQuote;
```

API
---

[](#api)

*`wrapi`* is an open ended framework and is not restricted any one or a set of public APIs. All APIs providing HTTP interface to access the endpoints can be wrapped by *`wrapi`* so that you can quickly build your client application.

### Endpoint definition

[](#endpoint-definition)

`method` &amp; `path`/`url` are required.

- `method` - Any one of the HTTP [methods](https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html)
- `path` - route path to API Endpoint. Supports `express` style [path params](http://expressjs.com/en/4x/api.html#req.params)
- `query` - an associative array with name-value pairs. This is optional. Useful where resources are identified via query string parameters
- `url` - fully qualified uri string to override. Useful when api calls connect to a different endpoints

### Client object

[](#client-object)

The *`wrapi`* object conveniently provides the client interface to the API. Create it by calling `new` *`wrapi\wrapi()`*.

The constructor takes the following arguments:

1. `baseURL` - The base url for the API. eg. `https://api.github.com/repos/guzzle/guzzle/contributors`
2. `endpoints` - The array listing the endpoints of the API. Provide an empty array or a partial list and register endpoints later.
3. `options` - Optional parameter. *`wrapi`* uses [Guzzle](http://docs.guzzlephp.org/) module to connect to API server. The `options` parameter is the same [`options`](http://docs.guzzlephp.org/en/latest/request-options.html) parameter used in `Guzzle``request`.

### Register function

[](#register-function)

Add endpoints to client object.

```
$client(function_name, endpoint_definition)
```

1. `function_name` - Alias for the endpoint, also the name of the function to call.
2. `endpoint_definition` - Array defining the endpoint.

### Function calls

[](#function-calls)

Call the API via the function in the client object. Arguments to the function depend on the API declaration in the endpoints array.

Provide the arguments in the following order:

1. named `params` in the url path of the endpoint. eg. `$client->contributors('guzzle', 'guzzle')   // guzzle (owner) & guzzle (repo) are path params`
2. `querystring` as an associative array with name-value pairs. eg. `$client->contributors(array("since" => 364)  // querystring ?since=364`
3. `body` - JSON content for `POST` or `PUT` methods. Skip this argument if not required.

Examples
--------

[](#examples)

In examples [folder](examples).

License
-------

[](#license)

[MIT](LICENSE)

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity39

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 97.3% 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 ~158 days

Recently: every ~197 days

Total

6

Last Release

3039d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1656913?v=4)[Palani Kumanan](/maintainers/palanik)[@palanik](https://github.com/palanik)

---

Top Contributors

[![palanik](https://avatars.githubusercontent.com/u/1656913?v=4)](https://github.com/palanik "palanik (36 commits)")[![kuredev](https://avatars.githubusercontent.com/u/1259315?v=4)](https://github.com/kuredev "kuredev (1 commits)")

---

Tags

apiGuzzlewrapperfunctionfunctionsrestful

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/palanik-wrapi/health.svg)

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

###  Alternatives

[antoinelemaire/aircall-php

Aircall API client built on top of Guzzle 6

1049.6k](/packages/antoinelemaire-aircall-php)

PHPackages © 2026

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