Giter VIP home page Giter VIP logo

plugin-http's Introduction

HTTP Plugin

Phergie plugin for Provide HTTP functionality to other plugins.

Build Status

Install

To install via Composer, use the command below, it will automatically detect the latest version and bind it with ~.

composer require phergie/phergie-irc-plugin-http 

See Phergie documentation for more information on installing and enabling plugins.

Requirements

The HTTP plugin requires the DNS plugin to be setup for DNS resolving.

Configuration

return [

    'plugins' => [

        // dependency
        new \Phergie\Plugin\Dns\Plugin, // Needed to do DNS lookups

        new \Phergie\Plugin\Http\Plugin([

            // All configuration is optional

            'dnsResolverEvent' => 'dns.resolver', // Event for retrieving the DNS resolver, defaults to 'dns.resolver'
            
            'guzzleClientOptions' => [], // Array with options passed into the Guzzle Client constructor (don't set a handler in here it will be overwritten)

        ]),

    ]
];

Usage

Get Guzzle HTTP Client

$this->emitter->emit('http.client', [
    function (GuzzleHttp\Client $client) {
        // Make HTTP requests as documented on the Guzzle docs: http://guzzle.readthedocs.org/en/latest/clients.html#asynchronous-requests
        // When making requests make sure to pass the future flag as documented: http://guzzle.readthedocs.org/en/latest/faq.html#can-guzzle-send-asynchronous-requests
    },
]);

Make a HTTP request

$this->emitter->emit('http.request', [new \Phergie\Plugin\Http\Request([
    'url' => 'https://github.com/',                     // Required
    'resolveCallback' => function($response) { // Required
        // Data received do something with it
    },
    'method' => 'GET',                                  // Optional, request method
    'headers' => array(),                               // Optional, headers for the request
    'body' => '',                                       // Optional, request body to write after the headers
    'rejectCallback' => function($error) {},            // Optional, callback that gets triggered on connection errors
])]);

A note about resolveCallback and rejectCallback. rejectCallback will only fire on a socket error. So resolveCallback will be called no matter what HTTP status code as the request has been successful on a connection level. Choosing the appropriate response to a status code is up to the event callee.

Tests

To run the unit test suite:

curl -s https://getcomposer.org/installer | php
php composer.phar install
cd tests
../vendor/bin/phpunit

License

Released under the MIT License. See LICENSE.

plugin-http's People

Contributors

elazar avatar matthewtrask avatar nfauchelle avatar scrutinizer-auto-fixer avatar sitedyno avatar svpernova09 avatar wyrihaximus avatar

Watchers

 avatar  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.