PHPackages                             phplicengine/phplicengine-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. phplicengine/phplicengine-api

ActiveLibrary[API Development](/categories/api)

phplicengine/phplicengine-api
=============================

API for PHPLicengine

2.2.2(6y ago)91155ApachePHPPHP &gt;=5.5.0

Since Oct 12Pushed 6y ago2 watchersCompare

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

READMEChangelog (3)DependenciesVersions (4)Used By (0)

[![Latest Stable Version](https://camo.githubusercontent.com/5750d5e6e1f1cb44b4e6991ce89b3e0c3a2b1d076baef14eacd90024889c8e39/68747470733a2f2f706f7365722e707567782e6f72672f7068706c6963656e67696e652f7068706c6963656e67696e652d6170692f762f737461626c65)](https://packagist.org/packages/phplicengine/phplicengine-api)[![Total Downloads](https://camo.githubusercontent.com/a9608b4d4cb21cc29c948842abac0941618b2dad1a87be4620076b0e83b7e616/68747470733a2f2f706f7365722e707567782e6f72672f7068706c6963656e67696e652f7068706c6963656e67696e652d6170692f646f776e6c6f616473)](https://packagist.org/packages/phplicengine/phplicengine-api)

API
===

[](#api)

PHPLicengine API

You can use this API library for any needs, not necessarily for PHPLicengine API. With PHPLicengine API library you can contact with any RESTApi server and receive response as json/xml and parse them.

Contents
--------

[](#contents)

- [Usage](#usage)
- [Installation](#installation)
- [Sample](#sample)
- [Manual](#manual)
- [Changelog](#changelog)
- [License](#license)

Usage
-----

[](#usage)

You can use this API library for any needs, not necessarily for PHPLicengine API. To do so, you should call Api class directly or implement your own service class. You can call [setApiKeyVar() method](https://github.com/phplicengine/phplicengine-api/blob/master/lib/PHPLicengine/Api/Api.php#L67) of Api class to change the Api key header variable according to requirements of your Api server, and [setValidResponseHeader() method](https://github.com/phplicengine/phplicengine-api/blob/master/lib/PHPLicengine/Api/Result.php#L106) of Result class, if your Api server returns a response Api header, and you need to get it. You can get it with \[getReference() method\] (). By default these are setup according to requirements of PHPLicengine API.

You can directly call Api class for your PHPLicengine API, but for your convenience we've created service classes that you can call them instead of Api class, for example see [Client service](https://github.com/phplicengine/phplicengine-api/blob/master/examples/client.md) class.

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

[](#installation)

Versioning is the same as PHPLicengine. For general usage you can install any version as desired. But if you want to use PHPLicengine service classes, you should install the same version as your PHPLicengine or lower if there is not the same version.

```
composer require phplicengine/phplicengine-api x.x.x

```

Sample
------

[](#sample)

```
use PHPLicengine\Api\Api;

$api = new Api();

// If your RESTApi server requires an Api key header, you can pass it to constructor of Api class:
// $api = new Api("API key goes here.");
// $api->setApiKeyVar("X-RESTAapi-Key");

// SSL verification is enabled by default. You can use below to disable it.
// $api->disableSslVerification();
// You can use below to enable it again.
// $api->enableSslVerification();

// timeout is set to 30 by default. You can use below to change it if needed.
// $api->setTimeout(60);

// Sets the host:port of a proxy to be used by cURL. If this is not set,
// no proxy is used. For example, $api->setCurlProxy('proxy.example.com:3128');
// $api->setCurlProxy($proxy);

// get(), post(), delete(), put(), patch() methods are available.
// first parameter is url, second is query as array, third is header as array.
// Only first parameter (i.e. $url) is required.
$response = $api->get($url, null, null);

// For debug purposes only:
// print_r($api->getCurlInfo());
// print_r($response->getHeaders());
// print($response->getBody());
// exit;

// for logging purposes only:
// print($api->getResponse());
// print_r($api->getRequest());
// print_r($response->getHeaders());
// print($response->getBody());

if (!$api->isCurlError()) { // checks for cURL error

    if ($response->isOk()) { // checks for Code:200

        // If your RESTApi server returns a particular header as a valid response,
        // you can set here:
        $response->setValidResponseHeader("X-ApiServer-Response");

        // This checks if the valid response header above is available or not.
        if ($response->isValidResponse()) {

            if ($response->isError()) { // if response of api has error
                print($response->getErrorMessage());
            } else {
                // $dataAsObject = $response->getDecodedJson();
                // echo $dataAsObject->username;
                // echo $response->getContentType();
                // You can get X-ApiServer-Response header value like below:
                // echo $response->getReference();
                print("");
                print_r($response->getJsonAsArray());
            }

        } else {
            print("Invalid server response.");
        }

    } else { // response code is not 200:Ok
        die("Error ".$response->getResponseCode()." : ".$response->getReasonPhrase());
    }

} else { // api curl Error occurs.
    die("Curl Connection: ".$api->getCurlErrno()." : ".$api->getCurlError());
}
```

NOTE: Usually RESTApi servers return a json response with 'error' and ' message' elements if an error occurs. If your RESTApi server returns another format, you'd need to customize [isError()](https://github.com/phplicengine/phplicengine-api/blob/master/lib/PHPLicengine/Api/Result.php#L121) and [getErrorMessage()](https://github.com/phplicengine/phplicengine-api/blob/master/lib/PHPLicengine/Api/Result.php#L126) methods in Result class.

Manual
------

[](#manual)

#### Custom cURL Options

[](#custom-curl-options)

If you need to add some CURLOPT\_\* constants that are not enabled by default, you can call setCurlCallback() method to add them.

```
use PHPLicengine\Api\Api;
$api = new Api();
$api->setCurlCallback(function($ch, $params, $headers, $method) {
      curl_setopt($ch, CURLOPT_USERAGENT, 'some agent');
      curl_setopt($ch, CURLOPT_COOKIE, 'foo=bar');
      curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
      curl_setopt($ch, CURLOPT_USERPWD, "username:password");
});
$api->post($url, $params, $headers);
```

#### Upload Files

[](#upload-files)

You can upload files with POST method and with this array structure as post parameter. Note that 'filename' must be absolute path to file.

```
Array
(
    [files] => Array
        (
            [0] => Array
                (
                    [filename] => /path/to/file1.txt
                )
            [1] => Array
                (
                    [filename] => /path/to/file2.txt
                )
        )
    [foo] => bar
)
```

#### Service Classes

[](#service-classes)

For service classes usage, See [here](https://github.com/phplicengine/phplicengine-api/tree/master/examples).

Changelog
---------

[](#changelog)

New methods: (v2.x.x)

```
// for logging purposes only:
print($api->getResponse());
print_r($api->getRequest());

// Sets the host:port of a proxy to be used by cURL. If this is not set,
// no proxy is used. For example, $api->setCurlProxy('proxy.example.com:3128');
$api->setCurlProxy($proxy);
```

New methods: (v2.2.2)

Added `patch()` method.

License
-------

[](#license)

PHPLicengine Api is distributed under the Apache License. See [License](https://github.com/phplicengine/phplicengine-api/blob/master/LICENSE).

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity60

Established project with proven stability

 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 ~735 days

Total

3

Last Release

2402d ago

PHP version history (2 changes)2.1.0PHP &gt;=5.3.0

2.2.2PHP &gt;=5.5.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/df056bd5f03afaa010b4e3d2da153560c36b7af3fa280cd05bd05b47d4e9d135?d=identicon)[phplicengine](/maintainers/phplicengine)

---

Top Contributors

[![phplicengine](https://avatars.githubusercontent.com/u/13603184?v=4)](https://github.com/phplicengine "phplicengine (247 commits)")

---

Tags

apirestapi

### Embed Badge

![Health badge](/badges/phplicengine-phplicengine-api/health.svg)

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

###  Alternatives

[phplicengine/bitly

Bitly API v4

22277.3k](/packages/phplicengine-bitly)[m165437/laravel-blueprint-docs

API Blueprint Renderer for Laravel

22779.0k](/packages/m165437-laravel-blueprint-docs)

PHPackages © 2026

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