Giter Club home page Giter Club logo

http-client's Introduction

HttpClient Component

Build Status

Basic HTTP/1.0 client.

Basic usage

Requests are prepared using the Client#request() method. Body can be sent with Request#write(). Request#end() finishes sending the request (or sends it at all if no body was written).

Request implements WritableStreamInterface, so a Stream can be piped to it. Response implements ReadableStreamInterface.

Interesting events emitted by Request:

  • response: The response headers were received from the server and successfully parsed. The first argument is a Response instance.
  • error: An error occured.
  • end: The request is finished. If an error occured, it is passed as first argument. Second and third arguments are the Response and the Request.

Interesting events emitted by Response:

  • data: Passes a chunk of the response body as first argument
  • error: An error occured.
  • end: The response has been fully received. If an error occured, it is passed as first argument

Example

<?php

$loop = React\EventLoop\Factory::create();

$dnsResolverFactory = new React\Dns\Resolver\Factory();
$dnsResolver = $dnsResolverFactory->createCached('8.8.8.8', $loop);

$factory = new React\HttpClient\Factory();
$client = $factory->create($loop, $dnsResolver);

$request = $client->request('GET', 'https://github.com/');
$request->on('response', function ($response) {
    $response->on('data', function ($data) {
        // ...
    });
});
$request->end();

TODO

  • gzip content encoding
  • chunked transfer encoding
  • keep-alive connections
  • following redirections

http-client's People

Contributors

arnaud-lb avatar cboden avatar clue avatar cursedcoder avatar igorw avatar wyrihaximus avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.