Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sendgrid/php-http-client
SendGrid's PHP HTTP Client for calling APIs
https://github.com/sendgrid/php-http-client
Last synced: about 1 month ago
JSON representation
SendGrid's PHP HTTP Client for calling APIs
- Host: GitHub
- URL: https://github.com/sendgrid/php-http-client
- Owner: sendgrid
- License: mit
- Created: 2016-02-26T17:34:36.000Z (almost 9 years ago)
- Default Branch: main
- Last Pushed: 2024-01-24T12:33:20.000Z (11 months ago)
- Last Synced: 2024-09-08T12:11:00.691Z (4 months ago)
- Language: PHP
- Homepage: https://sendgrid.com
- Size: 405 KB
- Stars: 125
- Watchers: 163
- Forks: 66
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
- awesome-http - SendGrid HTTP Client - http-client) ![GitHub commit activity](https://img.shields.io/github/commit-activity/y/sendgrid/php-http-client) (Programming Languages / PHP)
README
![SendGrid Logo](twilio_sendgrid_logo.png)
[![Tests](https://github.com/sendgrid/php-http-client/actions/workflows/test-and-deploy.yml/badge.svg)](https://github.com/sendgrid/php-http-client/actions/workflows/test-and-deploy.yml)
[![Latest Version on Packagist](https://img.shields.io/packagist/v/sendgrid/php-http-client.svg?style=flat-square)](https://packagist.org/packages/sendgrid/php-http-client)
[![Twitter Follow](https://img.shields.io/twitter/follow/sendgrid.svg?style=social&label=Follow)](https://twitter.com/sendgrid)
[![GitHub contributors](https://img.shields.io/github/contributors/sendgrid/php-http-client.svg)](https://github.com/sendgrid/php-http-client/graphs/contributors)
[![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)**Quickly and easily access any RESTful or RESTful-like API.**
If you are looking for the SendGrid API client library, please see [this repo](https://github.com/sendgrid/sendgrid-php).
# Announcements
All updates to this library are documented in our [CHANGELOG](CHANGELOG.md).# Table of Contents
- [Installation](#installation)
- [Quick Start](#quick-start)
- [Usage](#usage)
- [How to Contribute](#contribute)
- [Thanks](#thanks)
- [About](#about)
- [Support](#support)
- [License](#license)## 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](http://getcomposer.org), you should be. It's an excellent way to manage dependencies in your PHP application.
```json
{
"require": {
"sendgrid/php-http-client": "^4.1.1"
}
}
```Then at the top of your PHP script require the autoloader:
```php
require __DIR__ . '/vendor/autoload.php';
```Then from the command line:
```bash
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](https://github.com/sendgrid/php-http-client.git) and [sendgrid-php](https://github.com/sendgrid/sendgrid-php.git):
```
$ 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`:
```
$ cd /path/to/your/app
$ touch loader.php
```And add the code below to the `loader.php`:
```php
# Quick Start
Here is a quick example:
`GET /your/api/{param}/call`
```php
// 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.
```php
// 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.- [Usage Examples](USAGE.md)
## Environment Variables
You can do the following to create a .env file:
```cp .env_example .env```
Then, just add your API Key into your .env file.
We encourage contribution to our libraries, please see our [CONTRIBUTING](CONTRIBUTING.md) guide for details.
Quick links:
- [Feature Request](CONTRIBUTING.md#feature-request)
- [Bug Reports](CONTRIBUTING.md#submit-a-bug-report)
- [Improvements to the Codebase](CONTRIBUTING.md#improvements-to-the-codebase)
- [Review Pull Requests](CONTRIBUTING.md#code-reviews)We were inspired by the work done on [birdy](https://github.com/inueni/birdy) and [universalclient](https://github.com/dgreisen/universalclient).
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.
If you need help using SendGrid, please check the [Twilio SendGrid Support Help Center](https://support.sendgrid.com).