PHPackages                             roemerb/php7-rest - 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. roemerb/php7-rest

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

roemerb/php7-rest
=================

A simple REST client for PHP 7.0+

1.0(9y ago)0111MITPHPPHP &gt;=7.0

Since Jun 14Pushed 9y ago1 watchersCompare

[ Source](https://github.com/Roemerb/php7-rest)[ Packagist](https://packagist.org/packages/roemerb/php7-rest)[ Docs](https://github.com/roemerb/php7-rest)[ RSS](/packages/roemerb-php7-rest/feed)WikiDiscussions master Synced 2w ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

[![Build Status](https://camo.githubusercontent.com/8c39ac488de17e7c20091f060df243297aaebfcdf951eb2a5afec0e0c96ac6f2/68747470733a2f2f7472617669732d63692e6f72672f526f656d6572622f706870372d726573742e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/Roemerb/php7-rest)

php7-rest
=========

[](#php7-rest)

php7-rest is a very simple Http REST client with some optimization for PHP v7.0+. It's not necessarily intended to be very feature-rich or even to be widely used, but merely to provide a simple API for specifying REST API behaviour.

### Install

[](#install)

If you'd like to install this library, I recommend using Composer:

```
composer require roemeb/php7-rest
```

Though, as this library does not have any dependencies - it only requires `ext-curl` -, you can also just clone this repository and start using `src/RestClient.php`.

### Usage

[](#usage)

**Initialisation**

Initialize a client for an API like so:

```
require_once('vendor/autoload.php');

use RestClient\RestClient;

$client = new RestClient(RestClient::HTTPS, 'api.myhost.com', ['version' => 2]);
```

You only have to specify the scheme and host. If you need to use any kind of authentication, you can do this by adding headers. Generating oauth tokens is not currently part of this library.

```
$token = Oauth::gen_token($credentials);

$client->addHeader('Authorization', 'Bearer ' . $token);
```

**Options**

There are some options that can be specified upon initialisation:

- `version` Version of your API. Will be appended to host as path (i.e. `myhost.com/v2/`)
- `port` Does your API run on an obscure port? Specify it here.
- `cert` File path to certificate bundle that will be loaded to avoid curl error 60
- `content_type` Custom value for the `Content-Type` header. Defaults to `application/json`. Set to `false` if you don't want this header at all.
- `user_agent` Custom value for the `User-Agent` header. Defaults to `Php7Rest/{Version}`. Set to `false` if you don't want this header at all.
- `insecure` Set to true to dissable curl host verification.

The header options may also be set by using `$client->addHeader($name, $value)`. It will override the defaults.

**Resources**

Querying data can be done in one of two ways. Either you can register resources which will be magically called, or your existing resource class can extend the `RestResource` class provided in this library.

**Registering resources**

Registering resources is quite simple. Simply provide a name and an array of methods this resource supports. Additionally, if your resource supports non-default methods, you can register these as well. If these require an ID, it will be included in the request automatically.

```
$client->register('people', ['list', 'get', 'create']);
$client->registerMethod('people', [
	'name' 		=> 'address',
	'method' 		=> '{id}/formatted_address',
	'http_method'	=> RestClient::HTTP_GET // Or just 'GET'/'get'/'Get'
]);

/**
* This will call:
* GET https://api.myhost.com/people/v2/{id}
*/
$client->people->get($id);

// We can call custom methods the same way
$client->people->address($id);
```

**Extending `RestResource`**

```
class Person extends RestResource
{
	public function __construct()
	{
		// Just give the parent constructor some information
		parent::__construct($restClient, strtolower(__CLASS__);
	}
}

$people = new Person();
$people->get($id);
```

**Closures**

All methods support closures, so you don't have to wait for a response from an API to continue your business logic. The response will be included as an argument to your function. Use closures as follows:

```
// Initiate an API call...
$client->people->get($id, function($response) {
	// Do something with $response
});

// ...and continue to do other stuff in the meantime.
```

###  Health Score

25

—

LowBetter than 35% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity58

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

3304d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/756897?v=4)[complexity](/maintainers/complexity)[@Complexity](https://github.com/Complexity)

---

Top Contributors

[![Roemerb](https://avatars.githubusercontent.com/u/4710404?v=4)](https://github.com/Roemerb "Roemerb (12 commits)")

---

Tags

httpclientrestcurlphp 7php 7.0

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/roemerb-php7-rest/health.svg)

```
[![Health](https://phpackages.com/badges/roemerb-php7-rest/health.svg)](https://phpackages.com/packages/roemerb-php7-rest)
```

###  Alternatives

[apimatic/unirest-php

Unirest PHP

225.6M149](/packages/apimatic-unirest-php)[zoonman/pixabay-php-api

PixabayClient is a PHP HTTP client library to access Pixabay's API

3355.9k](/packages/zoonman-pixabay-php-api)[e-moe/guzzle6-bundle

Integrates Guzzle 6 into your Symfony application

12262.2k1](/packages/e-moe-guzzle6-bundle)

PHPackages © 2026

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