Skip to content

Commit

Permalink
Merge pull request #1 from Art4/add-changelog
Browse files Browse the repository at this point in the history
Create CHANGELOG.md
  • Loading branch information
Art4 authored Oct 6, 2022
2 parents 965ee73 + ae72a70 commit f8a19c8
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased](https://github.com/Art4/WP-Requests-PSR18-Adapter/compare/09aae5d7deac8058c5a25c1d951cd350d066ad6e...HEAD)

### Added

- Library created from pull request
50 changes: 50 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,53 @@
Use [WordPress/Requests](https://github.com/WordPress/Requests) as a [PSR-18](https://www.php-fig.org/psr/psr-18/) HTTP client adapter.

Requires PHP 7.0+

## Why?

Requests is a HTTP library written in PHP, that [lacks of support for PSR-7](https://github.com/WordPress/Requests/issues/320) and also for PSR-18 because of the compatability with PHP 5.6+.

[I've created a PR in Requests to add PSR-7 support](https://github.com/WordPress/Requests/pull/768) but I would be able to use it today. So I created this library. If one day Requests nativly supports PSR-7 and PSR-18, this library will become obsolete.

## How to use

### Installation with Composer

WordPress/Requests PSR-18 Adapter is [available on Packagist](https://packagist.org/packages/art4/requests-psr18-adapter) and can be installed using [Composer](https://getcomposer.org/).

```bash
composer require art4/requests-psr18-adapter
```

### Example

```php
<?php

// First, include the Composer autoload.php
require_once dirname(__DIR__) . '/vendor/autoload.php';

// Define Requests options
$options = [
'proxy' => '127.0.0.1:8080',
'transport' => $customTransport,
// other Requests options
];

// Create the HTTP client
$httpClient = new \Art4\Requests\Psr\HttpClient($options);

// Create a PSR-7 request and optional set other headers
$request = $httpClient->createRequest('GET', 'http://httpbin.org/get');
$request = $request->withHeader('Accept', 'application/json');

try {
// Send the request
$response = $httpClient->sendRequest($request);
} catch (\Psr\Http\Client\ClientExceptionInterface $th) {
// Handle errors
throw $th;
}

// See the result
var_dump($response);
```

0 comments on commit f8a19c8

Please sign in to comment.