Giter Club home page Giter Club logo

rest-curlclient-php's Introduction

Basic REST client using cURL

Simple implementation that supports PUT, GET, POST, DELETE and uses cURL. Based on rest-client-php https://github.com/shurikk/rest-client-php, thanks to him for his job.

It is made for those like me, when there are some situations in which pecl_http can not be used.

Supports GET, POST, PUT, DELETE HTTP methods. All options from cURL can be passed to constructor as an array.

Response from calling curl_getinfo() and curl_exec() are respectively in $client->response_info and $client->response_object

Examples

require 'rest_client.php';
$c = new RestCurlClient();

GET request

$res = $c->get('http://www.yahoo.com');

Posting raw POST data

$res = $c->post(
  'http://api.example.com/create', json_encode(array('name' => 'foobar'))
);

Sending a form using POST

$res = $c->post(
  'http://www.example.com/form', array('name' => 'foobar'))
);

Sending custom HTTP headers

$res = $c->post(
  'http://www.example.com/form', json_encode(array('name' => 'foobar')),
  array(
    CURLOPT_HTTPHEADER => array(
      'X-My-App' => 'foobar/1.0',
      'Content-type' => 'application/json'
    )
  )
);

Basic HTTP authentication

$res = $c->post(
  'http://www.example.com/form', json_encode(array('name' => 'foobar')),
  array(
    CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
    CURLOPT_USERPWD => 'username:password'
  )
);

Notice that all authentication schemes supported by cURL can be used here.

PUT request

$res = $c->post(
  'http://www.example.com/upload.txt', 'PUT request data'
);

References

Contributors

rest-curlclient-php's People

Contributors

davidmpaz avatar merkdev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

rest-curlclient-php's Issues

Little mistake in the example

Hi,

I just wanted to tell you there were a small issue on the example: You need to instanciate a RestCurlClient not a RestClientCurl.

Thank you for this repo :)

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.