req
req copied to clipboard
"Request" local files
Hi there. First of all, thanks for this great work.
I'm currently developing an application which needs to request some user provided URLs. My issue is related with testing it.
Testing has a lot to do with trusting, and I trust that req works fine because it has its own test suite and it is being used by the community. For this reason, I don't like and I don't see the reason why my tests should be non-deterministic because of the need to reach external end-points which could be not available at some point.
For my own confidence, it would be enough to be able to provide in my test suite a location for a local file which content would act as a response body.
Of course, I see some inconvenient with this. Maybe it is pushing the abstraction out of its scope, because, which method should that request have and which headers should the response have?
Maybe another module Nework.HTTP.Req.Testing could be added implementing the needed logic, but surely some changes in the core system would be necessary. Maybe adding another Scheme constructor called Local, or maybe to make req function not depend on Url but on something implementing a new Url type class.
How do you see it? Am I missing a better approach?
Thanks
I think I found the solution.
Note that the current version of the library works a bit differently. You still should be able to use req', see how pure-tests is written.
I see. The problem is that what I'm testing is a function that internally uses req and not req'. You can think of this function as a function taking an URL as parameter, performing the request with req and returning a handcrafted version of the response within an IO.
So I think I come back to my first thought... Considering the option to support the file scheme in req.
Does http-client support file scheme?
No, as far as I know, it doesn't :disappointed:
The most logical way to add this is to add the feature to http-client and then add a new scheme to Req (Req is built on top of http-client).
I agree this should be the way to go. I submitted an issue there.