2017 © Pedro Peláez
 

library php-http-client

HTTP REST client, simplified for PHP

image

sendgrid/php-http-client

HTTP REST client, simplified for PHP

  • Tuesday, April 10, 2018
  • by thinkingserious
  • Repository
  • 126 Watchers
  • 29 Stars
  • 1,493,484 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 46 Forks
  • 6 Open issues
  • 26 Versions
  • 15 % Grown

The README.md

SendGrid Logo, (*1)

Tests Latest Version on Packagist Twitter Follow GitHub contributors MIT licensed, (*2)

Quickly and easily access any RESTful or RESTful-like API., (*3)

If you are looking for the SendGrid API client library, please see this repo., (*4)

Announcements

All updates to this library are documented in our CHANGELOG., (*5)

Table of Contents

, (*6)

Installation

Prerequisites

  • PHP version 7.3, 7.4, 8.0, or 8.1

Install with Composer

Add php-http-client to your composer.json file. If you are not using Composer, you should be. It's an excellent way to manage dependencies in your PHP application., (*7)

{
  "require": {
    "sendgrid/php-http-client": "^4.1.1"
  }
}

Then at the top of your PHP script require the autoloader:, (*8)

require __DIR__ . '/vendor/autoload.php';

Then from the command line:, (*9)

composer install

Install without Composer

You should create a lib directory in the directory of your application and clone to lib repositories php-http-client and sendgrid-php:, (*10)

$ cd /path/to/your/app
$ mkdir lib
$ cd lib
$ git clone https://github.com/sendgrid/php-http-client.git

In the next step you should create loader.php:, (*11)

$ cd /path/to/your/app
$ touch loader.php

And add the code below to the loader.php:, (*12)

<?php

require_once __DIR__ . '/lib/php-http-client/lib/Client.php';
require_once __DIR__ . '/lib/php-http-client/lib/Response.php';

After it you can use the php-http-client library in your project:, (*13)

<?php

include __DIR__ . '/loader.php';

$client = new SendGrid\Client();

, (*14)

Quick Start

Here is a quick example:, (*15)

GET /your/api/{param}/call, (*16)

// include __DIR__ . '/loader.php';
require 'vendor/autoload.php';
$apiKey = YOUR_SENDGRID_API_KEY;
$authHeaders = [
    'Authorization: Bearer ' . $apiKey
];
$client = new SendGrid\Client('https://api.sendgrid.com', $authHeaders);
$param = 'foo';
$response = $client->your()->api()->_($param)->call()->get();

var_dump(
    $response->statusCode(),
    $response->headers(),
    $response->body()
);

POST /your/api/{param}/call with headers, query parameters and a request body with versioning., (*17)

// include __DIR__ . '/loader.php';
require 'vendor/autoload.php';
$apiKey = YOUR_SENDGRID_API_KEY;
$authHeaders = [
    'Authorization: Bearer ' . $apiKey
];
$client = new SendGrid\Client('https://api.sendgrid.com', $authHeaders);
$queryParams = [
    'hello' => 0, 'world' => 1
];
$requestHeaders = [
    'X-Test' => 'test'
];
$data = [
    'some' => 1, 'awesome' => 2, 'data' => 3
];
$param = 'bar';
$response = $client->your()->api()->_($param)->call()->post($data, $queryParams, $requestHeaders);

var_dump(
    $response->statusCode(),
    $response->headers(),
    $response->body()
);

If there is an issues with the request, such as misconfigured CURL SSL options, an InvalidRequest will be thrown with message from CURL on why the request failed. Use the message as a hit to troubleshooting steps of your environment., (*18)

, (*19)

Usage

Environment Variables

You can do the following to create a .env file:, (*20)

cp .env_example .env, (*21)

Then, just add your API Key into your .env file., (*22)

, (*23)

How to Contribute

We encourage contribution to our libraries, please see our CONTRIBUTING guide for details., (*24)

Quick links:, (*25)

, (*26)

Thanks

We were inspired by the work done on birdy and universalclient., (*27)

, (*28)

About

php-http-client is maintained and funded by Twilio SendGrid, Inc. The names and logos for php-http-client are trademarks of Twilio SendGrid, Inc., (*29)

, (*30)

Support

If you need help using SendGrid, please check the Twilio SendGrid Support Help Center., (*31)

, (*32)

License

The MIT License (MIT), (*33)

The Versions

10/04 2018

dev-master

9999999-dev http://github.com/sendgrid/php-http-client

HTTP REST client, simplified for PHP

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

api rest http sendgrid fluent

10/04 2018

3.9.6

3.9.6.0 http://github.com/sendgrid/php-http-client

HTTP REST client, simplified for PHP

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

api rest http sendgrid fluent

27/03 2018

3.9.5

3.9.5.0 http://github.com/sendgrid/php-http-client

HTTP REST client, simplified for PHP

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

api rest http sendgrid fluent

23/03 2018

3.9.4

3.9.4.0 http://github.com/sendgrid/php-http-client

HTTP REST client, simplified for PHP

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

api rest http sendgrid fluent

23/03 2018

dev-fix_constructor_sig

dev-fix_constructor_sig http://github.com/sendgrid/php-http-client

HTTP REST client, simplified for PHP

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

api rest http sendgrid fluent

11/03 2018

3.9.3

3.9.3.0 http://github.com/sendgrid/php-http-client

HTTP REST client, simplified for PHP

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

api rest http sendgrid fluent

10/03 2018

3.9.2

3.9.2.0 http://github.com/sendgrid/php-http-client

HTTP REST client, simplified for PHP

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

api rest http sendgrid fluent

10/03 2018

dev-12_union

dev-12_union http://github.com/sendgrid/php-http-client

HTTP REST client, simplified for PHP

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

api rest http sendgrid fluent

09/03 2018

3.9.1

3.9.1.0 http://github.com/sendgrid/php-http-client

HTTP REST client, simplified for PHP

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

api rest http sendgrid fluent

08/03 2018

3.9.0

3.9.0.0 http://github.com/sendgrid/php-http-client

HTTP REST client, simplified for PHP

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

api rest http sendgrid fluent

08/03 2018

dev-81_insecure

dev-81_insecure http://github.com/sendgrid/php-http-client

HTTP REST client, simplified for PHP

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

api rest http sendgrid fluent

23/01 2018

dev-docker-update

dev-docker-update http://github.com/sendgrid/php-http-client

HTTP REST client, simplified for PHP

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

api rest http sendgrid fluent

13/09 2017

3.8.0

3.8.0.0 http://github.com/sendgrid/php-http-client

HTTP REST client, simplified for PHP

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

api rest http sendgrid fluent

05/05 2017

3.7.0

3.7.0.0 http://github.com/sendgrid/php-http-client

HTTP REST client, simplified for PHP

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

api rest http sendgrid fluent

02/03 2017

3.6.0

3.6.0.0 http://github.com/sendgrid/php-http-client

HTTP REST client, simplified for PHP

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

api rest http sendgrid fluent

22/12 2016

dev-thinkingserious-patch-1

dev-thinkingserious-patch-1 http://github.com/sendgrid/php-http-client

HTTP REST client, simplified for PHP

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

api rest http sendgrid fluent

17/11 2016

3.5.1

3.5.1.0 http://github.com/sendgrid/php-http-client

HTTP REST client, simplified for PHP

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

api rest http sendgrid fluent

19/10 2016

3.5.0

3.5.0.0 http://github.com/sendgrid/php-http-client

HTTP REST client, simplified for PHP

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

api rest http sendgrid fluent

27/09 2016

3.4.0

3.4.0.0 http://github.com/sendgrid/php-http-client

HTTP REST client, simplified for PHP

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

api rest http sendgrid fluent

13/09 2016

3.3.0

3.3.0.0 http://github.com/sendgrid/php-http-client

HTTP REST client, simplified for PHP

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

api rest http sendgrid fluent

11/06 2016

3.1.0

3.1.0.0 http://github.com/sendgrid/php-http-client

HTTP REST client, simplified for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

api rest http sendgrid fluent

07/06 2016

3.0.0

3.0.0.0 http://github.com/sendgrid/php-http-client

HTTP REST client, simplified for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

api rest http sendgrid fluent

11/05 2016

2.0.2

2.0.2.0 http://github.com/sendgrid/php-http-client

HTTP REST client, simplified for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

api rest http sendgrid fluent

11/05 2016

2.0.1

2.0.1.0 http://github.com/sendgrid/php-http-client

HTTP REST client, simplified for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

api rest http sendgrid fluent

21/03 2016

1.0.1

1.0.1.0 http://github.com/sendgrid/php-http-client

HTTP REST client, simplified for Python

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

api rest http sendgrid fluent

21/03 2016

1.0.0

1.0.0.0 http://github.com/sendgrid/php-http-client

HTTP REST client, simplified for Python

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

api rest http sendgrid fluent