arthurh / rest-proxifier
proxy your rest api
Requires
- composer/composer: 1.0.0-alpha9
- hassankhan/config: 0.7.*
- jenssegers/proxy: ~2.2
- league/plates: ~3.1
- league/route: ~1.1
- monolog/monolog: ~1.13
- orange-opensource/cf-helper-php: 1.3.1
- sphring/sphring: ~0.9
- tedivm/stash: 0.12.*
- vectorface/whip: 0.2.*
Requires (Dev)
- filp/whoops: ~1.1
- phpunit/phpunit: ~4.5
README
The goal of this project is to proxy your rest api.
Why do this?
First, it was initialized when I found that some rest api doesn't handle CORS.
This project will reinject CORS headers for angularjs project for example.
This project will also cache response for read request.
NOTE: Rest-proxifier use pathinfo
so set your web server to use it.
NOTE2: This project is Cloud Foundry Ready, so you can also use it inside Cloud Foundry to handle uaa rest api for example.
Installation
Through Composer, obviously:
$ composer create-project arthurh/rest-proxifier path/
How to use
You can use rest-proxifier in multiple ways:
- Proxy from cnnfig file
- Proxy from CloudFoundry Services if you use CloudFoundry
- Proxy from database entries
Theses 3 ways can be used in same time, there is no limit.
For simple use, look at config/default.yml
:
proxyfy: - api: http://example.com route: /api #this is optionnal #request-header: # header-key: header-value #response-header: # header-key: header-value #response-content: ~ admin-ui: true #set to false to remove admin interface admin-ui-root: /admin #path to admin ui rewriting: false #set to true if you use rewriting to point directly on index.php caching-time: 20 minutes #set to false to remove caching log-request: true #set to false to stop logs user request to proxify database: false #or uri to database, e.g: mysql://root:password@localhost/mydb or special uri for sqlite: sqlite:/path, this is optionnal
This file can be rewrite in json
or in xml
too, it uses this dependency noodlehaus/config so follow schemas from this dependency if you don't want use yaml.
For this default config there is an example, a route is already set.
What you should do to try is to go to http://<my hostname>/index.php/api
and rest-proxifier will respond the page http://example.com
with CORS headers.
If you do http://<my hostname>/index.php/api/other/verb/for/api
rest-proxifier will respond http://example.com/other/verb/for/api
.
Admin interface
By default you have an interface located on http://<my hostname>/index.php/admin
.
You can use it to add more proxy only on a database.
Proxies from config file can't be modify with this interface with the goal make accessible all the time theses proxies.
For Cloud Foundry user
This part is only for people who use the Cloud Foundry PaaS.
You can create a service which contain proxy
(use regex to find service) in his name with this json value for example:
[ { "api": "http://example.com", "route": "/api" } ]
And rest-proxifier will auto-bind to this service
You can also create a database service which should contains at least one of theses values in its name (use regex to find service):
my
(for mysql)db
database
oracle
oci
postgres
pgsql
maria
And rest-proxifier will auto-bind database to this service