Requests icon indicating copy to clipboard operation
Requests copied to clipboard

Add PSR-7 support

Open Art4 opened this issue 3 years ago • 0 comments

This PR will add PSR-7 HTTP message support to Requests. This means that Requests will be able to process any PSR-7 Psr\Http\Message\RequestInterface implementation and response with a PSR-7 Psr\Http\Message\ResponseInterface implementation.

Pull Request Type

  • [x] I have checked there is no other PR open for the same change.

This is a:

  • [x] New feature

Context

@jrfnl stated in https://github.com/WordPress/Requests/issues/320#issuecomment-1236301755 that PSR-7 support would be a useful addition. Therefore I started with the implementation as a draft. Since I don't have any experience in contributing to Requests yet (I've read the .github/CONTRIBUTING.md), I appreciate early feedback to avoid gross errors early on.

Detailed Description

The plan is that the PSR-7 implementation will be built as a wrapper around the existing classes in the WpOrg\Requests\Psr namespace. This way there should be no breaking changes and the usage is optional. This is also important because PSR-7 has some limitations, such as missing multible requests.

Long term goal is as I mentioned here a PSR-18 implementation to be able to use Requests as a PSR-18 HTTP client. However, this will require PHP 7.0+ and is therefore not part of this PR. Nevertheless, this PR already includes a class that is compatible with PSR-18 and PSR-17 RequestFactory, but does not yet rely on the interfaces. This must be implemented in a future PR after bumping the PHP version to 7.0+.

Work progress

  • [x] Implement request factory compatible to Psr\Http\Message\RequestFactoryInterface
  • [x] Implement Psr\Http\Message\UriInterface
  • [x] Implement Psr\Http\Message\RequestInterface
  • [x] Implement Psr\Http\Message\StreamInterface
  • [x] Implement stream factory compatible to Psr\Http\Message\StreamFactoryInterface
  • [ ] Implement Psr\Http\Message\ResponseInterface
  • [ ] Implement HTTP client compatible to Psr\Http\Client\ClientInterface

Quality assurance

  • [x] This change does NOT contain a breaking change (fix or feature that would cause existing functionality to change).
  • [x] I have commented my code, particularly in hard-to-understand areas.
  • [x] I have added unit tests to accompany this PR.
  • [x] The (new/existing) tests cover this PR 100%.
  • [x] I have (manually) tested this code to the best of my abilities.
  • [ ] My code follows the style guidelines of this project.

Documentation

For new features:

  • [ ] I have added a code example showing how to use this feature to the examples directory.
  • [ ] I have added documentation about this feature to the docs directory. If the documentation is in a new markdown file, I have added a link to this new file to the Docs folder README.md file.

Art4 avatar Sep 08 '22 12:09 Art4