<commit_before>php-rest
========

A rest client for PHP to make consuming rest api easier. This library will automatically decode response to json where response content type is `application/json`. JSON is used by most modern rest services for serialization. So you can focus on your application code without worrying for decoding.

This library depends on php5_curl library. You can install it using `sudo apt-get install php5-curl` or `yum install php5-curl`

The constructor takes an optional base url, this makes consuming api from a single source much easier.

##Api
```php
//constructor
new RestClient($baseURL="", $debugMode=false)

//methods
public function doGet($url, $params=array())
public function doPost($url, $params)
public function doPut($url, $params)
public function doDelete($url, $params=array())
```

##Examples

```php
<?php
  include '../lib/santoshsahoo/phprest/restclient.class.php';

  use santoshsahoo\phprest\RestClient;
     
  $client = new RestClient('http://api.example.com/v1');
  $data = $client->doPost('/sum', array('x'=>1, 'y'=>2)); //json
  $result = $data['result'];
?>
```

Or as

```php
<?php
  include '../lib/santoshsahoo/phprest/restclient.class.php';

  use santoshsahoo\phprest\RestClient;
     
  $client = new RestClient();
  $data = $client->doPut('http://api.example.com/v2/update-user', array('x'=>1, 'y'=>2)); //json
  $result = $data['result'];
?>
```

### running unittest
`phpunit.phar restclienttest.php`

This test depends on Flask webapp included in the /test directory<commit_msg>Updated the example doc with get and plain text<commit_after>php-rest
========

A rest client to make consuming rest services easier in PHP. This library will automatically decode json response to php array where response content type is `application/json`. JSON serialization is used in most modern rest services. So you can focus on your application code without worrying about decoding your self.

This library depends on *php5 curl* library. You can install it using `sudo apt-get install php5-curl` or `yum install php5-curl`

The constructor takes an optional base url, this makes consuming api from a single source much easier.

##Api
```php
//constructor
new RestClient($baseURL="", $debugMode=false)

//methods
public function doGet($url, $params=array())
public function doPost($url, $params)
public function doPut($url, $params)
public function doDelete($url, $params=array())
```

##Examples

```php
<?php
  include '../lib/santoshsahoo/phprest/restclient.class.php';

  use santoshsahoo\phprest\RestClient;
     
  $client = new RestClient('https://api.example.com/v1');
  
  $apiversion = $client->doGet('/version'); //text
  
  $data = $client->doPost('/sum', array('x'=>1, 'y'=>2)); //json
  $result1 = $data['result'];
    
  $data = $client->doPut('/multiply', array('x'=>5, 'y'=>3));
  $result2 = $data['result'];
?>
```

Or as

```php
<?php
  include '../lib/santoshsahoo/phprest/restclient.class.php';

  use santoshsahoo\phprest\RestClient;
     
  $client = new RestClient();
  $user = array('email'=>'<EMAIL>', 'name'=>'<NAME>', 'age'=>25);
  $data = $client->doPut('http://api.example.com/v2/user', $user); //json
  $uid = $data['uid'];
?>
```

### running unittest
`phpunit.phar restclienttest.php`

This test depends on Flask webapp included in the /test directory
{'fraction_non_alphanumeric': 0.1537075953167217, 'fraction_numerical': 0.006604623236265386, 'mean_word_length': 4.6, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 26, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2512035', 'n_tokens_mistral': 1063, 'n_tokens_neox': 1020, 'n_words': 337}