Git Product home page Git Product logo

php.curl's Introduction

php.curl

PCurl is a PHP client library for RESTful web services.

PCurl supports GET/POST/PUT/DELETE request methods. Unlike other similar libaries supports also HTTPS certificates verification.

Composer Installation

To install PCurl, use the following composer require statement:

{
    "require": {
        "purplecode/pcurl": "dev-master"
    }
}

or just copy-paste content of src/ to your libs.

Usage

PCurl.php

Simple GET

$pcurl = new PCurl('http://www.google.pl');
$response = $pcurl->get('/')->getBody();

Simple GET via HTTPS with certificate verification (more examples in test package)

$pcurl = new PCurl('https://www.google.pl');
$pcurl->useSSLCertificate(<path to crt/pem file>);
$response = $pcurl->get('/')->getBody();

and a similar example without it

$pcurl = new PCurl('https://www.google.pl');
$pcurl->ignoreSSLCertificate();
$response = $pcurl->get('/')->getBody();

Sample POST

$pcurl = new PCurl('http://some.fancy.page');
$pcurl->proxy(host, port);
$pcurl->auth(user, pass);
$pcurl->header('Cache-Control: no-cache');
$pcurl->contentType('application/xml');
$response = $pcurl->post('/igipigiel/xml', '<a>makapaka</a>')->getBody();

PJsonCurl.php

Class similar to PCurl, the only difference is that the input/output is passed through json_encode/json_decode.

$pcurl = new PJsonCurl('http://www.app.com/json');
$response = $pcurl->put('/', array('a' => 'b'));
echo $response->getBody()['c'];

PObjectCurl.php

Class similar to PJsonCurl, the difference is that the input/output is passed through serialize/deserialize methods. Requires JMS\Serializer library or JMSSerializerBundle Symfony2 bundle.

$pcurl = new PObjectCurl('http://www.prettifier.com/json', JMS\Serializer\SerializerInterface $serializer);
$pcurl->responseClass('My\App\Preety');
$uglyObject =  new My\App\Ugly();
$preetyObject = $pcurl->put('/', $uglyObject)->getBody();

Enjoy!

php.curl's People

Contributors

purplecode avatar

Watchers

James Cloos avatar Jacek Tomasiak 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.