|
| 1 | +# Table of Contents |
| 2 | +- [Installation](#installation) |
| 3 | +- [Quick Start](#quick-start) |
| 4 | +- [Usage](#usage) |
| 5 | + |
| 6 | +<a name="installation"></a> |
| 7 | +# Installation |
| 8 | + |
| 9 | +## Prerequisites |
| 10 | + |
| 11 | +- PHP version 5.6 or 7.0 |
| 12 | + |
| 13 | +## Install with Composer |
| 14 | + |
| 15 | +Add php-http-client to your `composer.json` file. If you are not using [Composer](http://getcomposer.org), you should be. It's an excellent way to manage dependencies in your PHP application. |
| 16 | + |
| 17 | +```json |
| 18 | +{ |
| 19 | + "require": { |
| 20 | + "sendgrid/php-http-client": "~3.8" |
| 21 | + } |
| 22 | +} |
| 23 | +``` |
| 24 | + |
| 25 | +Then at the top of your PHP script require the autoloader: |
| 26 | + |
| 27 | +```php |
| 28 | +require __DIR__ . '/vendor/autoload.php'; |
| 29 | +``` |
| 30 | + |
| 31 | +Then from the command line: |
| 32 | + |
| 33 | +```bash |
| 34 | +composer install |
| 35 | +``` |
| 36 | + |
| 37 | +## Install without Composer |
| 38 | + |
| 39 | +You should create directory `lib` in directory of your application and clone to `lib` repositories [php-http-client](https://github.com/sendgrid/php-http-client.git) and [sendgrid-php](https://github.com/sendgrid/sendgrid-php.git): |
| 40 | + |
| 41 | +``` |
| 42 | +$ cd /path/to/your/app |
| 43 | +$ mkdir lib |
| 44 | +$ cd lib |
| 45 | +$ git clone https://github.com/sendgrid/php-http-client.git |
| 46 | +$ git clone https://github.com/sendgrid/sendgrid-php.git |
| 47 | +``` |
| 48 | + |
| 49 | +In the next step you should create `loader.php`: |
| 50 | + |
| 51 | +``` |
| 52 | +$ cd /path/to/your/app |
| 53 | +$ touch loader.php |
| 54 | +``` |
| 55 | + |
| 56 | +And add to `loader.php` code below: |
| 57 | + |
| 58 | +```php |
| 59 | +<?php |
| 60 | + |
| 61 | +require_once __DIR__ . '/lib/php-http-client/lib/Client.php'; |
| 62 | +require_once __DIR__ . '/lib/php-http-client/lib/Response.php'; |
| 63 | +require_once __DIR__ . '/lib/sendgrid-php/lib/SendGrid.php'; |
| 64 | + |
| 65 | +``` |
| 66 | + |
| 67 | +After it you can use `php-http-client` library in your project: |
| 68 | + |
| 69 | +```php |
| 70 | +<?php |
| 71 | + |
| 72 | +include __DIR__ . '/loader.php'; |
| 73 | + |
| 74 | +$client = new SendGrid\Client(); |
| 75 | +``` |
| 76 | + |
| 77 | +<a name="quick-start"></a> |
| 78 | +# Quick Start |
| 79 | + |
| 80 | +Here is a quick example: |
| 81 | + |
| 82 | +`GET /your/api/{param}/call` |
| 83 | + |
| 84 | +```php |
| 85 | +// include __DIR__ . '/loader.php'; |
| 86 | +require 'vendor/autoload.php'; |
| 87 | +$global_headers = array('Authorization: Basic XXXXXXX'); |
| 88 | +$client = new SendGrid\Client('base_url', $global_headers); |
| 89 | +$response = $client->your()->api()->_($param)->call()->get(); |
| 90 | +print $response->statusCode(); |
| 91 | +print $response->headers(); |
| 92 | +print $response->body(); |
| 93 | +``` |
| 94 | + |
| 95 | +`POST /your/api/{param}/call` with headers, query parameters and a request body with versioning. |
| 96 | + |
| 97 | +```php |
| 98 | +// include __DIR__ . '/loader.php'; |
| 99 | +require 'vendor/autoload.php'; |
| 100 | +$global_headers = array('Authorization: Basic XXXXXXX'); |
| 101 | +$client = new SendGrid\Client('base_url', $global_headers); |
| 102 | +$query_params = array('hello' => 0, 'world' => 1); |
| 103 | +$request_headers = array('X-Test' => 'test'); |
| 104 | +$data = array('some' => 1, 'awesome' => 2, 'data' => 3); |
| 105 | +$response = $client->your()->api()->_($param)->call()->post('data', |
| 106 | + 'query_params', |
| 107 | + 'request_headers'); |
| 108 | +print $response->statusCode(); |
| 109 | +print $response->headers(); |
| 110 | +print $response->body(); |
| 111 | +``` |
| 112 | + |
| 113 | +<a name="usage"></a> |
| 114 | +# Usage |
| 115 | + |
| 116 | +- [Example Code](https://github.com/sendgrid/php-http-client/tree/master/examples) |
| 117 | + |
0 commit comments