trulyao/neat-http

An HTTP client/wrapper based on curL

1.0.0 2022-09-01 18:02 UTC

This package is auto-updated.

Last update: 2024-09-29 06:20:32 UTC


README

EXPERIMENTAL

A curL-based HTTP client. This is an experimental side-project, if you need something more robust and stable, you can check out GuzzleHTTP. Feel free to fork or make a PR too :)

Requirements

  • PHP 8.0+
  • CurL extension (ENABLE IN PHP.INI)

Installation

composer require trulyao/neat-http

Usage

<?php

use Trulyao\NeatHttp\Client;

$client = new Client(
    [
        'baseUrl' => 'http://example.com',
        'object' => true, // return object instead of array
        'headers' => [
            'Content-Type' => 'application/json',
            'Accept' => 'application/json',
        ],
    ] // optional base config
);

$variable1 = $client->get('1');

$variable2 = $client->post('', [
    'data' => [
         'title' => 'foo',
         'body' => 'bar',
         'userId' => 1,
    ],
]); // automatically serialized to JSON before sending
       

Check __tests__ for more usage example.