Popularity
1.2
Stable
Activity
0.3
-
11
6
1

Description

Consume any APIs with Bearer API client for PHP.

Monthly Downloads: 0
Programming language: PHP
License:
Tags: API     Third Party APIs     REST     JSON     Agent     Monitor    
Latest version: v2.1

Bearer PHP Client alternatives and similar libraries

Based on the "API" category.
Alternatively, view Bearer PHP Client alternatives based on common mentions on social networks and blogs.

Do you think we are missing an alternative of Bearer PHP Client or a related project?

Add another 'API' Library

README

Bearer PHP Client

This is the official PHP client for interacting with Bearer.sh.

Installation

Install the package by running:

composer require bearer/bearer-php

Usage

Get your Bearer Secret Key and integration id from the Dashboard and use the Bearer client as follows:

Calling any APIs

$bearer = new Bearer\Client('BEARER_SECRET_KEY'); // find it on https://app.bearer.sh/keys

$api = $bearer->integration('api_name');
$api->get('/api-endpoint');

More advanced examples

Note: to run the following examples, you'll need to activate the GitHub API first. To activate it, log in to the Dashboard then click on "Add an api" and select "GitHub API".

Passing query parameters

$bearer = new Bearer\Client('BEARER_SECRET_KEY'); // find it on https://app.bearer.sh/keys

$github = $bearer->integration('github');
$github->get('/users/bearer/repos', [ "query" => [ "direction" => "desc" ] ]);

Authenticating users

$bearer = new Bearer\Client('BEARER_SECRET_KEY'); // find it on https://app.bearer.sh/keys

$github = $bearer->integration('github');
$github
    ->auth("AUTH_ID") // Generate a user identity from the Dashboard
    ->put('/user/starred/bearer/bearer', [ "headers" => [ "Content-Length" => 0 ] ]);

Available methods

The following methods are available out-of-the-box: GET, POST, PUT, DELETE, OPTIONS. If you want to dynamically perform requests, use the request($method) function:

$bearer = new Bearer\Client('BEARER_SECRET_KEY'); // find it on https://app.bearer.sh/keys

$github = $bearer->integration('github');
$github
    ->auth("AUTH_ID") // Generate a user identity from the Dashboard
    ->request('PUT', '/user/starred/bearer/bearer', [ "headers" => [ "Content-Length" => 0 ] ]);

Setting the request timeout

You can customize your http client by specifying httpClientSettings as a Bearer\Client or \$bearer-integration parameter. By default Bearer client request and connection timeouts are set to 5 seconds. Bearer allows to increase the request timeout to up to 30 seconds

$bearer = new Bearer\Client('BEARER_SECRET_KEY', [CURLOPT_TIMEOUT => 10]); // sets timeout to 10 seconds

$github = $bearer->integration('github', [CURLOPT_CONNECTTIMEOUT => 1]); // sets connect timeout to 1 second
$github->get('/repos', [ "query" => [ "direction" => "desc" ] ]);

Learn more on how to use custom functions with Bearer.sh.

Development

Install composer

$ composer install
# run tests
$ vendor/bin/phpunit tests