103 |
- |
1 |
[](https://travis-ci.org/sendgrid/php-http-client)
|
|
|
2 |
|
|
|
3 |
**Quickly and easily access any RESTful or RESTful-like API.**
|
|
|
4 |
|
|
|
5 |
If you are looking for the SendGrid API client library, please see [this repo](https://github.com/sendgrid/sendgrid-php).
|
|
|
6 |
|
|
|
7 |
# Announcements
|
|
|
8 |
|
|
|
9 |
All updates to this library is documented in our [CHANGELOG](https://github.com/sendgrid/php-http-client/blob/master/CHANGELOG.md).
|
|
|
10 |
|
|
|
11 |
# Installation
|
|
|
12 |
|
|
|
13 |
## Prerequisites
|
|
|
14 |
|
|
|
15 |
- PHP version 5.6 or 7.0
|
|
|
16 |
|
|
|
17 |
## Install with Composer
|
|
|
18 |
|
|
|
19 |
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.
|
|
|
20 |
|
|
|
21 |
```json
|
|
|
22 |
{
|
|
|
23 |
"require": {
|
|
|
24 |
"sendgrid/php-http-client": "3.5.1"
|
|
|
25 |
}
|
|
|
26 |
}
|
|
|
27 |
```
|
|
|
28 |
|
|
|
29 |
Then at the top of your PHP script require the autoloader:
|
|
|
30 |
|
|
|
31 |
```php
|
|
|
32 |
require __DIR__ . '/vendor/autoload.php';
|
|
|
33 |
```
|
|
|
34 |
|
|
|
35 |
Then from the command line:
|
|
|
36 |
|
|
|
37 |
```bash
|
|
|
38 |
composer install
|
|
|
39 |
```
|
|
|
40 |
|
|
|
41 |
# Quick Start
|
|
|
42 |
|
|
|
43 |
Here is a quick example:
|
|
|
44 |
|
|
|
45 |
`GET /your/api/{param}/call`
|
|
|
46 |
|
|
|
47 |
```php
|
|
|
48 |
require 'vendor/autoload.php';
|
|
|
49 |
$global_headers = array(Authorization: Basic XXXXXXX);
|
|
|
50 |
$client = SendGrid\Client('base_url', 'global_headers');
|
|
|
51 |
$response = $client->your()->api()->_($param)->call()->get();
|
|
|
52 |
print $response->statusCode();
|
|
|
53 |
print $response->headers();
|
|
|
54 |
print $response->body();
|
|
|
55 |
```
|
|
|
56 |
|
|
|
57 |
`POST /your/api/{param}/call` with headers, query parameters and a request body with versioning.
|
|
|
58 |
|
|
|
59 |
```php
|
|
|
60 |
require 'vendor/autoload.php';
|
|
|
61 |
$global_headers = array(Authorization: Basic XXXXXXX);
|
|
|
62 |
$client = SendGrid\Client('base_url', 'global_headers');
|
|
|
63 |
$query_params = array('hello' => 0, 'world' => 1);
|
|
|
64 |
$request_headers = array('X-Test' => 'test');
|
|
|
65 |
$data = array('some' => 1, 'awesome' => 2, 'data' => 3);
|
|
|
66 |
$response = $client->your()->api()->_($param)->call()->post('data',
|
|
|
67 |
'query_params',
|
|
|
68 |
'request_headers');
|
|
|
69 |
print $response->statusCode();
|
|
|
70 |
print $response->headers();
|
|
|
71 |
print $response->body();
|
|
|
72 |
```
|
|
|
73 |
|
|
|
74 |
# Usage
|
|
|
75 |
|
|
|
76 |
- [Example Code](https://github.com/sendgrid/php-http-client/tree/master/examples)
|
|
|
77 |
|
|
|
78 |
## Roadmap
|
|
|
79 |
|
|
|
80 |
If you are intersted in the future direction of this project, please take a look at our [milestones](https://github.com/sendgrid/php-http-client/milestones). We would love to hear your feedback.
|
|
|
81 |
|
|
|
82 |
## How to Contribute
|
|
|
83 |
|
|
|
84 |
We encourage contribution to our libraries, please see our [CONTRIBUTING](https://github.com/sendgrid/php-http-client/blob/master/CONTRIBUTING.md)) guide for details.
|
|
|
85 |
|
|
|
86 |
Quick links:
|
|
|
87 |
|
|
|
88 |
- [Feature Request](https://github.com/sendgrid/php-http-client/blob/master/CONTRIBUTING.md#feature_request)
|
|
|
89 |
- [Bug Reports](https://github.com/sendgrid/php-http-client/blob/master/CONTRIBUTING.md#submit_a_bug_report)
|
|
|
90 |
- [Sign the CLA to Create a Pull Request](https://github.com/sendgrid/php-http-client/blob/master/CONTRIBUTING.md#cla)
|
|
|
91 |
- [Improvements to the Codebase](https://github.com/sendgrid/php-http-client/blob/master/CONTRIBUTING.md#improvements_to_the_codebase)
|
|
|
92 |
|
|
|
93 |
# Thanks
|
|
|
94 |
|
|
|
95 |
We were inspired by the work done on [birdy](https://github.com/inueni/birdy) and [universalclient](https://github.com/dgreisen/universalclient).
|
|
|
96 |
|
|
|
97 |
# About
|
|
|
98 |
|
|
|
99 |
php-http-client is guided and supported by the SendGrid [Developer Experience Team](mailto:dx@sendgrid.com).
|
|
|
100 |
|
|
|
101 |
php-http-client is maintained and funded by SendGrid, Inc. The names and logos for php-http-client are trademarks of SendGrid, Inc.
|
|
|
102 |
|
|
|
103 |
![SendGrid Logo]
|
|
|
104 |
(https://uiux.s3.amazonaws.com/2016-logos/email-logo%402x.png)
|