https://github.com/endpot/php-rest-proxy
A php rest proxy script based on guzzle
https://github.com/endpot/php-rest-proxy
php proxy rest
Last synced: 5 months ago
JSON representation
A php rest proxy script based on guzzle
- Host: GitHub
- URL: https://github.com/endpot/php-rest-proxy
- Owner: endpot
- License: mit
- Created: 2017-10-21T14:37:11.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-10-31T00:57:41.000Z (over 7 years ago)
- Last Synced: 2025-05-13T18:33:59.117Z (about 1 year ago)
- Topics: php, proxy, rest
- Language: PHP
- Homepage:
- Size: 13.7 KB
- Stars: 10
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# php-rest-proxy
## About
This project is aimed to ultilize a rest proxy with php basing on Guzzle. Up to now, the script works fine for the most common request method (GET/POST/PUT/DELETE/OPTIONS). When data is submitted with POST method and contain multipart/form-data content, the script would create a new MultipartStream with global constant $_POST and $_FILES, and then transfer to target uri. The script also supports simple middleware within which you can deal with the request/response.
## 关于
该项目基于Guzzle实现请求的转发,包括但不限于GET/POST/PUT/DELETE/OPTIONS等方法。当请求方法为POST,且内容类型为multipart/form-data时,由于PHP的特性,从php://input中获取不到原始的数据,脚本会解析POST和FILES数组生成MultipartStream,再进行转发。该脚本还支持简单的中间件,分别作用于请求转发前后,对请求和响应进行处理。
## Installation
Install using composer:
```
composer require endpot/php-rest-proxy
```
## Example
```php
// create proxy instance
$proxy = new \Proxy\Proxy();
// set target url
$targetUrl = 'http://httpbin.org/';
// create psr7 request based on the global parameters
$request = $proxy->fromGlobals();
// add middlewares
// forward request to target
$response = $proxy->addMiddleware('ExampleMiddleware')
->forward($request)
->to($targetUrl);
// get and show the response
echo $response->getBody();
```
## License
It is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT).