PHPackages                             darkorsa/cordo-gateway - 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. darkorsa/cordo-gateway

ActiveLibrary[API Development](/categories/api)

darkorsa/cordo-gateway
======================

Gateway for API calls

1.5.0(5y ago)02[5 issues](https://github.com/darkorsa/cordo-gateway/issues)[5 PRs](https://github.com/darkorsa/cordo-gateway/pulls)MITPHP

Since Jul 16Pushed 3y agoCompare

[ Source](https://github.com/darkorsa/cordo-gateway)[ Packagist](https://packagist.org/packages/darkorsa/cordo-gateway)[ RSS](/packages/darkorsa-cordo-gateway/feed)WikiDiscussions master Synced 5d ago

READMEChangelog (1)Dependencies (26)Versions (15)Used By (0)

cordo-gateway
=============

[](#cordo-gateway)

[![Latest Version on Packagist](https://camo.githubusercontent.com/8486daf65a849b11649d990ec7b250c30da415885e37ea0ae856ee5dda660972/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6461726b6f7273612f636f72646f2d676174657761792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/darkorsa/cordo-gateway)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/fbd7fc2db4221bbe4d4adc0d817fd04fcd9a0c23edecf6ecef527b84c9d97cb7/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6461726b6f7273612f636f72646f2d676174657761792f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/darkorsa/cordo-gateway)[![Coverage Status](https://camo.githubusercontent.com/51aaba2db846e045c7a3e63c18f4ff03b9ff8b056cfab3ded4d8de3169121172/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f6461726b6f7273612f636f72646f2d676174657761792e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/darkorsa/cordo-gateway/code-structure)[![Quality Score](https://camo.githubusercontent.com/19e46e01cf10079643addb009ec0afb190d5de76e84b3648b27d57b67f304194/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6461726b6f7273612f636f72646f2d676174657761792e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/darkorsa/cordo-gateway)[![Total Downloads](https://camo.githubusercontent.com/b09600483d1da04c84654296862dfdbb38120f6d112160d9adfc0ea63676a427/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6461726b6f7273612f636f72646f2d676174657761792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/darkorsa/cordo-gateway)

Cordo API Gateway - protection, caching, analytics &amp; monitoring.

What is it? What is it for?
---------------------------

[](#what-is-it-what-is-it-for)

An API gateway is an API management tool that acts as reverse proxy and is located between a client and a backend service (or collection of services).

Most common use cases:

- protection from overuse and abuse
- analytics and monitoring
- gathering multiple API calls into one for optimization
- caching

Requirements
------------

[](#requirements)

- PHP 7.4.0 or newer
- Apache/Nginx
- PHP Redis extension (nosql db for for request caching and rate limiting)

Install
-------

[](#install)

First make sure that you have *Redis* expansions installed. To check it run:

```
$ php -i |grep redis
```

If any of them is missing you can install it from [PECL](https://pecl.php.net/) repository:

```
$ sudo pecl install redis

# restart PHP
$ sudo service php7.4-fpm restart
```

Create your new project folder and within this folder type:

```
$ composer create-project darkorsa/cordo-gateway ./
```

Then copy `.env_example` file and rename it to `.env` and complete it with your configuration data.

Usage
-----

[](#usage)

### Api Key

[](#api-key)

First set your `API_KEY` in `.env` file, that will extort sending `X-Api-Key` header with `API_KEY` value on each request to the gateway.

This can disabled by commenting `ApiKeyMiddleware` middleware in *public/index.php*.

```
$router->addMiddleware(new ApiKeyMiddleware()); // comment this line
```

> Note that X-Api-Key can be also used by rate limiting function.

### Defining routes

[](#defining-routes)

Since the API gateway is a proxy for the target API you will need to register routes for handling the upcoming requests. This can be done in *public/index.php*:

```
(new App\UsersRoutes($router, $container, 'https://apiurladdress.com'))->register();
```

Place you routes class somewhere in *app/* folder.

Example of routes class:

```
