webeweb/curl-library

Interact with web API in your projects

v1.1 2017-11-14 11:55 UTC

README

Build Status Coverage Status License composer.lock SensioLabsInsight

Interact with web API in your projects.

curl-library uses a rolling release based on git master branch which is considered stable.

Installation

Open a command console, enter your project directory and execute the following command to download the latest stable version of this package:

$ composer require webeweb/curl-library "~1.0@dev"

This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.

Usage


	// Initialize the POST request.
	$request = new CURLPostRequest(new CURLConfiguration(), "/resource-path");
	$request->getConfiguration()->setHost("http://domain.tld");
	$request->addQueryData("id", 1);
	$request->addPostData("firstname", "John");
	$request->addPostData("lastname", "DOE");
	...

	// Call the POST request.
	$response = $request->call();

	// Make something with the response.
	...

Requests available :

  • CURLDeleteRequest
  • CURLGetRequest
  • CURLHeadRequest
  • CURLOptionsRequest
  • CURLPatchRequest
  • CURLPostRequest
  • CURLPutRequest

Customize


class MyCustomRequest extends AbstractCURLRequest {

	/**
	 * Constructor.
	 *
	 * @param CURLConfiguration $configuration The configuration.
	 * @param string $resourcePath The resource path.
	 * @throws InvalidHTTPMethodException Throws an invalid HTTP method exception if the method is not implemented.
	 */
	public function __construct(CURLConfiguration $configuration, $resourcePath) {
		parent::__construct(self::METHOD_GET, $configuration, $resourcePath); //
	}

	...
}

Testing

To test the package, is better to clone this repository on your computer. Open a command console and execute the following commands to download the latest stable version of this package:

$ mkdir curl-library
$ cd curl-library
$ git clone git@github.com:webeweb/curl-library.git .
$ composer install

Once all required libraries are installed then do:

$ vendor/bin/phpunit

License

curl-library is released under the LGPL License. See the bundled LICENSE file for details.