2017 © Pedro Peláez
 

library pulsar-php

API request and response, without using CURL.

image

khalyomede/pulsar-php

API request and response, without using CURL.

  • Wednesday, June 20, 2018
  • by khalyomede
  • Repository
  • 1 Watchers
  • 0 Stars
  • 26 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 16 Versions
  • 4 % Grown

The README.md

Pulsar-php

API request and response, without using CURL., (*1)

Packagist PHP from Packagist Packagist, (*2)

 , (*3)

Pulsar-PHP logo

Summary

Installation

In your project, add the following dependency:, (*4)

composer require khalyomede/pulsar-php:3.*

PHP support

To use this library for PHP 5.3+ until 5.6, use the version 1.* of this library. Note the version 1 and 2 are no longer maintainted., (*5)

Examples

Sending a GET request

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

$content = pulsar()->get('https://jsonplaceholder.typicode.com/posts/1')->content();

print_r($content);
stdClass Object
(
  [userId] => 1
  [id] => 1
  [title] => sunt aut facere repellat provident occaecati excepturi optio reprehenderit
  [body] => quia et suscipit
suscipit recusandae consequuntur expedita et cum
reprehenderit molestiae ut ut quas totam
nostrum rerum est autem sunt rem eveniet architecto
)

Sending a POST request

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

$response = pulsar()->data([
  'title' => 'Test your PHP libraries with Matcha',
  'userId' => 1,
  'body' => 'Lorem ipsum'
])->post('https://jsonplaceholder.typicode.com/posts');

print_r($response->content());
stdClass Object
(
  [title] => Test your PHP libraries with Matcha
  [userId] => 1
  [body] => Lorem ipsum
  [id] => 101
)

Sending a PATCH request

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

$response = pulsar()->data([
  'name' => 'morpheus',
  'job' => 'zion resident'
])->patch('https://reqres.in/api/users/2');

print_r($response->content());
stdClass Object
(
  [name] => morpheus
  [job] => zion resident
  [updatedAt] => 2018-06-18T21:29:15.334Z
)

Sending a PUT request

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

$response = pulsar()->data([
    'name' => 'neo',
    'job' => 'developer at Metacortex'
])->put('https://reqres.in/api/users/2');

print_r($response->content());
stdClass Object
(
    [name] => neo
    [job] => developer at Metacortex
    [updatedAt] => 2018-06-20T09:46:44.267Z
)

Sending a DELETE request

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

$response = pulsar()->delete('https://reqres.in/api/users/2');

echo $response->code();
204

Sending a request to a non existing endpoint

In this case, you will always get a 404 status code and an empty response., (*6)

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

$response = pulsar()->get('https://a-non-existing-domain-hopefully.com/api/v1/post');

echo $response->code();
404

Get the response as an array

You can do so by using ->toArray() modifier:, (*7)

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

Get the response as an array

You can use the toArray() modifier for this purpose:, (*8)

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

$array = pulsar()->get('https://jsonplaceholder.typicode.com/posts/1')->toArray()->content();

print_r($array);

Which is the same as:, (*9)

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

$response = pulsar()->get('https://jsonplaceholder.typicode.com/posts/1');

$array = $response->toArray()->content();

print_r($array);
Array
(
  [userId] => 1
  [id] => 1
  [title] => sunt aut facere repellat provident occaecati excepturi optio reprehenderit
  [body] => quia et suscipit
suscipit recusandae consequuntur expedita et cum
reprehenderit molestiae ut ut quas totam
nostrum rerum est autem sunt rem eveniet architecto
)

Get the HTTP status code

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

$response = pulsar()->get('https://jsonplaceholder.typicode.com/posts/1');

echo $response->code();
200

Credits

The Versions

20/06 2018

dev-master

9999999-dev

API request and response, without using CURL.

  Sources   Download

MIT

The Requires

  • php >=7.2.0

 

The Development Requires

20/06 2018

v3.6.0

3.6.0.0

API request and response, without using CURL.

  Sources   Download

MIT

The Requires

  • php >=7.2.0

 

The Development Requires

18/06 2018

v3.5.0

3.5.0.0

API request and response, without using CURL.

  Sources   Download

MIT

The Requires

  • php >=7.2.0

 

The Development Requires

18/06 2018

v3.4.0

3.4.0.0

API request and response, without using CURL.

  Sources   Download

MIT

The Requires

  • php >=7.2.0

 

The Development Requires

18/06 2018

v3.3.0

3.3.0.0

API request and response, without using CURL.

  Sources   Download

MIT

The Requires

  • php >=7.2.0

 

The Development Requires

18/06 2018

v3.2.0

3.2.0.0

API request and response, without using CURL.

  Sources   Download

MIT

The Requires

  • php >=7.2.0

 

The Development Requires

18/06 2018

v3.1.0

3.1.0.0

API request and response, without using CURL.

  Sources   Download

MIT

The Requires

  • php >=7.2.0

 

The Development Requires

18/06 2018

v3.0.0

3.0.0.0

API request and response, without using CURL.

  Sources   Download

MIT

The Requires

  • php >=7.2.0

 

The Development Requires

18/06 2018

v2.1.0

2.1.0.0

API request and response, without using CURL.

  Sources   Download

MIT

The Requires

  • php >=7.2.0

 

The Development Requires

18/06 2018

v2.0.0

2.0.0.0

API request and response, without using CURL.

  Sources   Download

MIT

The Requires

  • php >=7.2.0

 

02/06 2017

1.0.9

1.0.9.0

Let you get JSON result from an API in a breeze (without using curl)

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

02/06 2017

1.0.8

1.0.8.0

Let you get JSON result from an API in a breeze (without using curl)

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

02/06 2017

1.0.7

1.0.7.0

Let you get JSON result from an API in a breeze (without using curl)

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

02/06 2017

1.0.6

1.0.6.0

Let you get JSON result from an API in a breeze (without using curl)

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

02/06 2017

1.0.5

1.0.5.0

Let you get JSON result from an API in a breeze (without using curl)

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

30/04 2017

0.0.1

0.0.1.0

Let you get JSON result from an API in a breeze (without using curl)

  Sources   Download

MIT

The Requires

  • php >=5.3.0