Skip to content

Curl based HTTP Client - Simple but effective OOP wrapper around Curl php lib

License

Notifications You must be signed in to change notification settings

DatingVIP/cURL

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cURL Bundle

Because cURL isn't simple enough ... apparently ...

Contained is a simple as you like Request and Response object for HTTP requests using the cURL API.

You can haz codez !

How to get shit done ...

Making a simple GET request:

require_once("vendor/autoload.php");

use DatingVIP\cURL\Request;
use DatingVIP\cURL\Response;

try {
	$response = (new Request())
		->setHeadersUsed(true)
		->get("http://www.example.com");
} catch (\RuntimeException $ex) {
	echo (string) $ex;
} finally {
	printf("Got %d bytes from %s in %.3f seconds\n",
		strlen((string)$response),
		$response->getURL(),
		$response->getTime());
}

Making a POST request:

require_once("vendor/autoload.php");

use DatingVIP\cURL\Request;
use DatingVIP\cURL\Response;

try {
	$response = (new Request())
		->setHeadersUsed(true)
		->post("http://www.example.com", ["hello" => "world"]);
} catch (\RuntimeException $ex) {
	echo (string) $ex;
} finally {
	printf("Posted %d bytes from %s in %.3f seconds\n",
		strlen((string)$response),
		$response->getURL(),
		$response->getTime());
}

If you like to be super verbose about everything for no good reason:

require_once("vendor/autoload.php");

use DatingVIP\cURL\Request;
use DatingVIP\cURL\Response;

try {
	$request = new Request([
		CURLOPT_HTTPHEADER => [
			"x-my-header" => "x-my-value"
		],
		CURLOPT_URL => "http://www.example.com"
	]);

	$response = new Response($request);
} catch (\RuntimeException $ex) {
	echo (string) $ex;
} finally {
	if ($response instanceof Response) {
		printf("Got %d bytes from %s in %.3f seconds\n",
			strlen((string)$response),
			$response->getURL(),
			$response->getTime());
	}
}

About

Curl based HTTP Client - Simple but effective OOP wrapper around Curl php lib

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%