Skip to content

A php package that handles API calls for you using curl, returns a DataObject with which you can interact using magic getters.

License

Notifications You must be signed in to change notification settings

REFUZIION/http-api-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Fuziion HttpApi Client

This PHP library provides a simple and versatile HTTP API client for interacting with APIs. It allows you to make GET and POST requests to an API, and it also includes a data handling feature for easily working with API response data.

Installation

You can install this library using Composer:

composer require fuziion/http-api-client

Usage

To use the Fuziion\HttpApi\Client class, follow these steps:

Import the necessary namespace:

use Fuziion\HttpApi\Client;

Create a Client instance by providing your API key and API URL:

$client = new Client('your-api-key', 'https://api.example.com');

Make GET or POST requests to the API:

GET Request:

$response = $client->get('/some/endpoint');
if ($response) {
    // Access API response data using magic getters
    echo $response->some_key; // Access 'some_key' in the response data
    // Or get the entire data array
    $data = $response->getData();
    print_r($data);
} else {
    // Handle the error
    echo "Error making the API GET request.";
}

POST Request:

$data = [
    'key1' => 'value1',
    'key2' => 'value2',
];

$response = $client->post('/some/endpoint', $data);
if ($response) {
    // Access API response data using magic getters
    echo $response->some_key;
    // Or get the entire data array
    $data = $response->getData();
    print_r($data);
} else {
    // Handle the error
    echo "Error making the API POST request.";
}

Replace 'your-api-key' and 'https://api.example.com' with your actual API key and URL. If the API you are trying to reach does not require an bearer token then just leave this field empty.

DataObject

The library includes a DataObject class for handling API response data with magic getters. It simplifies the process of accessing data within the API response.

use Fuziion\HttpApi\Data\DataObject;

$data = new DataObject(['key1' => 'value1', 'key2' => 'value2']);
echo $data->key1; // Access 'key1' in the data object

License

This library is licensed under the MIT License. See the LICENSE file for details.

About

A php package that handles API calls for you using curl, returns a DataObject with which you can interact using magic getters.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages