purescript-contrib/purescript-affjax

Custom HTTP/S agents

Opened this issue · 3 comments

xhr2 allows using a custom http/s agent for node: https://github.com/pwnall/node-xhr2/blob/567ec5f41f94f0bcb6d6b1f917be6506f43ce49a/src/001-xml_http_request.coffee#L262-L265.

It would be great if this could be set somehow, but not sure how this fits with purescript.

My usecase is wanting to plug in a proxying agent.

garyb commented

This answer applies to both this and #92:

I think we'll have to split Affjax's interface from its implementation if we want to support non-browser-XHR features, perhaps using https://github.com/slamdata/purescript-affjax-algebra or a typeclass or something. I don't really have time to work on it myself right now though.

Sorry about the slow reply!

I am interested in investing time into that. What method (typeclass, free monad) would be preferred and more importantly why? Is there another approach?

garyb commented

I guess since the algebra is already done just writing an alternative interpreter for that would be the fastest way to get this working, so I'd probably go with that.

The typeclass approach might be slight easier to defer to the main of the program as it can propagate as a constraint, so you don't have to explicitly pass the interpreter down, as you could just run it at the top level to turn it into Aff or something.

But generally I prefer the f-algebra approach as it gives you more options: you can (more easily) inspect or modify the requests, there is more flexibility in how the interpreter is implemented (in terms of accepting options, etc.). Also I prefer to avoid lawless typeclasses.

Either option is pretty good really, it's aesthetic as much as anything else. And you can even mix the two.