-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Request: PSGI protocol for HTTP::Tiny #130
Comments
See also perl-foundation-outreach/ideas#34 |
I would fear HTTP::Tiny not being so tiny anymore. Is it possible to do this with a subclass? |
My intention is to avoid suggesting the implementation details in the request, as this may distract people from supporting the outcome. For comparison sake, LWP has pluggable protocols. Furl::PSGI subclasses Furl and replaces key functions. Another approach may be via Class::Method::Modifiers whos maintainer I hear is a cool person. |
This is outside the scope of HTTP::Tiny. |
..but perhaps worth exploring in a role or subclass. |
The https://metacpan.org/pod/LWP::Protocol::PSGI module allows you to provide code that will called to respond to requests you make with LWP, rather than them going off to a server. The https://metacpan.org/pod/Furl::PSGI module does the same for the Furl library.
Something analogous, but for HTTP::Tiny, would be an amazing addition. The outcome would be vastly easier testing.
The pod of LWP::Protocol::PSGI has a good example, where a trivial dancer app is loaded to respond to LWP requests to google.com. In a test file, an author can mock a web service without having to start up a http daemon of some sort, and doesnt need to insert shims in their code either. Another example from the real world is https://metacpan.org/source/HAKOBE/WebService-SyoboiCalendar-0.02/t/lib/SyobocalMock.pm. The code being tested in entirely unaware of the subterfuge.
A version for HTTP::Tiny would do something very similar. Authors of code using HTTP::Tiny could use this new HTTP::Tiny w/ PSGI in their test suites to mock web services they want to test against.
LWP is multiprotocol, so lends itself to having PSGI added. For HTTP::Tiny to speak to something via PSGI, the code would need to do something like:
use HTTP::Tiny::FakeViaPSGI; # This fakes the HTTP::Tiny namespace
use HTTP::Tiny; # This then does nothing other than call HTTP::Tiny->import, as %INC already contains an entry for HTTP::Tiny
The text was updated successfully, but these errors were encountered: