Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jeroendedauw/postrequestsender
Micro library with interface for sending post requests. Includes test doubles and adapters
https://github.com/jeroendedauw/postrequestsender
Last synced: about 1 month ago
JSON representation
Micro library with interface for sending post requests. Includes test doubles and adapters
- Host: GitHub
- URL: https://github.com/jeroendedauw/postrequestsender
- Owner: JeroenDeDauw
- License: other
- Created: 2022-01-30T15:45:45.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2024-05-14T19:12:31.000Z (6 months ago)
- Last Synced: 2024-10-05T07:08:17.233Z (about 1 month ago)
- Language: PHP
- Homepage:
- Size: 47.9 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: COPYING.txt
Awesome Lists containing this project
README
# Post Request Sender
[![Build Status](https://img.shields.io/github/actions/workflow/status/JeroenDeDauw/PostRequestSender/ci.yml?branch=master)](https://github.com/JeroenDeDauw/PostRequestSender/actions?query=workflow%3ACI)
[![codecov](https://codecov.io/gh/JeroenDeDauw/PostRequestSender/branch/master/graph/badge.svg?token=GnOG3FF16Z)](https://codecov.io/gh/JeroenDeDauw/PostRequestSender)
[![Type Coverage](https://shepherd.dev/github/JeroenDeDauw/PostRequestSender/coverage.svg)](https://shepherd.dev/github/JeroenDeDauw/PostRequestSender)
[![Psalm level](https://shepherd.dev/github/JeroenDeDauw/PostRequestSender/level.svg)](psalm.xml)
[![Latest Stable Version](https://poser.pugx.org/jeroen/post-request-sender/version.png)](https://packagist.org/packages/jeroen/post-request-sender)
[![Download count](https://poser.pugx.org/jeroen/post-request-sender/d/total.png)](https://packagist.org/packages/jeroen/post-request-sender)Micro library with `PostRequestSender` interface and some [test doubles][doubles].
For the common cases where you do not need the complexity of the heavyweight libraries.
```php
interface PostRequestSender {/**
* @param string $url
* @param array $fields
*/
public function post( string $url, array $fields ): PostResponse;}
```## Usage
```php
$response = $requestSender->post( 'https://example.com', [ 'foo' => 'bar', 'baz' => 42 ] );
echo $response->body;
echo $response->statusCode;
```## Included implementations
Adapters
* `GuzzlePostRequestSender` Adapter for Guzzle
Decorators
* `LoggingPostRequestSender` Takes a `Psr\Log\LoggerInterface`
* `SpyPostRequestSender` Test double that records callsTest doubles
* `SpyPostRequestSender` Test double that records calls
* `StubPostRequestSender` Test double that returns a response provided in the constructor## Release notes
### 2.0.0 (2022-02-03)
* Ditched `ResponseInterface` in favor of a new simple value object `PostResponse`
### 1.0.1 (2022-02-02)
* Fixed behavior of `TestResponse::getBody`
### 1.0.0 (2022-01-30)
Initial release with
* `PostRequestSender` interface
* `SpyPostRequestSender` test double (and `PostRequest` value object)
* `StubPostRequestSender` test double
* `GuzzlePostRequestSender` implementation
* `LoggingPostRequestSender` decorator
* `TestResponse` helper implementation or PSR7 `ResponseInterface`[doubles]: https://en.wikipedia.org/wiki/Test_double