PHP code example of khalyomede / pulsar-php

1. Go to this page and download the library: Download khalyomede/pulsar-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

khalyomede / pulsar-php example snippets




$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
)



$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
)



$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
)



$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
)



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

echo $response->code();

204



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

echo $response->code();





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

print_r($array);



$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
)



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

echo $response->code();
bash
composer