Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

elsodev/Codeigniter-Basic-HTTP-Client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

3 Commits

Repository files navigation

Codeigniter Basic HTTP Client

Simplfying GET/POST requests using PHP cURL Only supports JSON format for now. XML, Images feature will be available soon.

Installation

Place HttpClient.php into your application/libraries

Usages

Initialization

$this->load->library('HttpClient', array(
	'headers' => array(
		 'Authorization: SomekeyHere',
 'Content-Type: application/json',
	),
	'data' => array(
		'somekey' => 'somedata',
		'anotherkey' => 'anotherkeydata'
	),
	'url' => 'http://somesite.com/api/1.0',
));

POST

if($this->httpclient->post()){
	var_dump($this->httpclient->getResults());
} else {
	echo $this->httpclient->getErrorMsg();
}

GET

//the only difference is ->get()
if($this->httpclient->get()){
	var_dump($this->httpclient->getResults());
} else {
	echo $this->httpclient->getErrorMsg();
}

Set Options

During library load, supplying parameters is optional. You can do it later with setOptions() method.

$this->load->library('HttpClient');
$this->httpclient->setOptions(
	array(
	'headers' => array(
		 'Authorization: SomekeyHere',
 'Content-Type: application/json',
	),
	'data' => array(
		'somekey' => 'somedata',
		'anotherkey' => 'anotherkeydata'
	),
	'url' => 'http://somesite.com/api/1.0',
));

Getting Results

This library provide two ways to obtain results.

  1. getResults(); which returns string
  2. getResultsArray(); which returns results in array if response is in JSON format.

Errors

To check for error :

if($this->httpclient->getError()){
	echo 'Error!'
}

To get error message :

	echo $this->httpclient->getErrorMsg();

Enjoy

Follow me on Twitter @elsodev for more updates

About

a basic HTTP client for your GET/POST requests

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

AltStyle によって変換されたページ (->オリジナル) /