Code Monkey home page Code Monkey logo

presto's Introduction

presto

PHP REST Orchestration

A REST client to access any services that support RESTful access or any HTTP access method. Supports all HTTP methods including: GET, POST, DELETE, PUT, OPTIONS, HEAD, AUTH, and custom. Simultaneous requests are supported through the use of a queue activation setting. Use of the queue will allow multiple requests to be processed in parallel, which can significantly speed up calls to multiple services or API end points.

Example

$request = new Shutterstock\Presto\Presto();
$r = $request->get('http://www.google.com');

Features

  1. Built-in support for all common REST call types
  2. Support for adding AUTH headers
  3. Supports queueing and parallel requests
  4. Support for passing a callback function for processing response
  5. Logging and profiling built-in
  6. Customizable timeouts and retries on a per request basis
  7. Support for setting user agent and referer

More Details

Presto relies on curl to make all requests. Many customization options are available including custom header additions, referrer, and user agent. Profiling is built-in and all the curl meta data and timing information are logged to assist with troubleshooting and optimization. Failed requests are logged as errors with optional exception throwing. A slow request configuration option allows logging of slow requests to the error log. Failed requests can automatically be retried a configureable number of times after a specified delay.

All request results are stored in a standardized Response object that includes meta data, header and request response data blocks. A meta data is_success entry is always present to indicate if the network request was successful or not. In the event of failure, there will be error information in the meta section.

Testing and Coverage

Presto has both unit and integration tests. To view coverage...

phpunit -c /tests/unit
phpunit -c /tests/integration

Queueing Example

Shutterstock\Presto\Presto::initQueue();

// callback function to process response
$rest_response = function($r) {
    if ($r->is_success) {
        echo "{$r->http_code} - {$r->url} " . round($r->total_time, 2) . "s\n";
    } else {
        echo "0 - {$r->url} {$r->error}\n";
    }
};

// URLs to hit, include one that will fail and another that will return a 404
$urls = [
    'http://www.google.com',
    'http://www.yahoo.com',
    'http://www.hfjkhfwekjhfkj.info',
    'http://www.bigstockphoto.com/qwerty',
];

// Create an array to hold Presto request objects
$requests = array();

foreach ($urls as $url) {
    $requests[$url] = new Shutterstock\Presto\Presto();
    $requests[$url]->queue_enabled = true;
    $requests[$url]->get($url, null, $rest_response);
}

// Process all queued requests
Shutterstock\Presto\Presto::processQueue();

presto's People

Contributors

jacobemerick avatar bbaisley avatar

Watchers

Jacques Marneweck avatar James Cloos 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.