2017 © Pedro Peláez
 

library dttp

http client for human

image

dancesmile/dttp

http client for human

  • Wednesday, July 11, 2018
  • by DanceSmile
  • Repository
  • 1 Watchers
  • 1 Stars
  • 10 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 11 % Grown

The README.md

Http client for human

Build Status License Latest Unstable Version Latest Stable Version, (*1)

安装

composer require dancesmile/dttp

单个请求直接访问

<?php 
use Dancesmile\Dttp;

// get request  http://localhost:9090/get?param1=1uery1&param2=query2
$response = Dttp::get("http://localhost:9090/get",[
    "param1" => "query1",
    "param2" => "query2"
]);
// post request http://localhost:9090/post and post www-form-urlencode data `username=username`
$response = Dttp::post("http://localhost:9090/post",[
    "username" => "username"
]);

// delete request 
$response = Dttp::delete("http://localhost:9090/delete");
// put request 
$response = Dttp::put("http://localhost:9090/put");
// patch request 
$response = Dttp::patch("http://localhost:9090/patch");

 ```

## 单个域名多个子链接访问 

```php
<?php
use Dancesmile\Dttp;

$client = Dttp::client(["base_uri" => "http://localhost:9090"]);
// get request  http://localhost:9090/get?param1=1uery1&param2=query2
$response = $client->get("/get",[
    "param1" => "query1",
    "param2" => "query2"
]);
// post  request http://localhost:9090/post and post www-form-urlencode data `username=username`
$response = $client->post("/post",[
    "username" => "username"
]);

响应返回 response

<?php
use Dancesmile\Dttp;

$response = Dttp::post("http://localhost:9090/post",[
    "username" => "username"
]);

$body = $response->body();
$json = $response->json();
$content_type = $response->header("Content-Type");
$headers = $response->headers();

提交数据

<?php
use Dancesmile\Dttp;

 Dttp::asJson()->post("http://localhost:9090/post",[
    "username" => "username"
 ]);

 Dttp::asString()->post("http://localhost:9090/post","hello");

 Dttp::asMultipart()->post("http://localhost:9090/post",[
    [
        "name" => "name",
        "contents" => "contens",
        "Content-Type" => "text/plain"
    ]
 ]);

 Dttp::asFormParams()->post("http://localhost:9090/post",[
    "username" => "username"
 ]);

属性设置

<?php
use Dancesmile\Dttp;

 $client = Dttp::asJson()->withHeaders([
    "dttp-version" => 1.0
 ]);

 $client->timeout(2);

 $client->accept("text/html");

 $client->redirect(true)

 $client->verify(false)

 $client->contentType("application/json");

 $client->post("http://localhost:9090/post",[
    "username" => "username"
 ]);

中间件

use Dancesmile\Dttp;

Dttp::addMiddware("test",function($request, array $options)use($handler)
{
    $this->runBeforeCallbacks($request, $options);
    return $handler($request, $options);
})->post("http://localhost:9090/post",[
    "username" => "username"
 ]);

 
Dttp::addMiddware("test",function($request, array $options)use($handler){
    $promise = $handler($request, $options);
    return $promise->then(
        function (ResponseInterface $response) {
            return $response;
        }
    );
})->post("http://localhost:9090/post",[
    "username" => "username"
 ]);

请求前置操作

<?php
use Dancesmile\Dttp;

Dttp::client("http://localhost:9090")->beforeSending(function($resquest, $option){

   //user code

})->get("/get")->json();

The Versions

11/07 2018

dev-master

9999999-dev

http client for human

  Sources   Download

MIT

The Requires

 

The Development Requires

by cailei

http request human http client

02/05 2018

v1.0.0

1.0.0.0

http client for human

  Sources   Download

MIT

The Requires

 

The Development Requires

by cailei

http request human http client