The documentation below is structured in such a way that the most
important information is presented first: you learn how to do HTTP
requests, how to embed them in the monad you have, and then it gives
you details about less-common things you may want to know about. The
documentation is written with sufficient coverage of details and
examples, and it's designed to be a complete tutorial on its own.
About the library
Req is an HTTP client library that attempts to be easy-to-use,
type-safe, and expandable.
“Easy-to-use” means that the library is designed to be
beginner-friendly so it's simple to add to your monad stack, intuitive
to work with, well-documented, and does not get in your way. Doing
HTTP requests is a common task and a Haskell library for this should
be approachable and clear to beginners, thus certain compromises were
made. For example, one cannot currently modify
ManagerSettings
of the default manager because the library always uses the same
implicit global manager for simplicity and maximal connection sharing.
There is a way to use your own manager with different settings, but it
requires more typing.
“Type-safe” means that the library tries to eliminate certain classes
of errors. For example, we have correct-by-construction URLs; it is
guaranteed that the user does not send the request body when using
methods like GET or OPTIONS, and the amount of implicit assumptions is
minimized by making the user specify their intentions in an explicit
form. For example, it's not possible to avoid specifying the body or
the method of a request. Authentication methods that assume HTTPS
force the user to use HTTPS at the type level.
“Expandable” refers to the ability to create new components without
having to resort to hacking. For example, it's possible to define your
own HTTP methods, create new ways to construct the body of a request,
create new authorization options, perform a request in a different
way, and create your own methods to parse a response.
Using with other libraries
- You won't need the low-level interface of http-client
most of the time, but when you do, it's better to do a qualified
import, because http-client has naming conflicts with
req.
- For streaming of large request bodies see the companion package
req-conduit:
https://hackage.haskell.org/package/req-conduit.
Lightweight, no risk solution
The library uses the following mature packages under the hood to
guarantee you the best experience:
It's important to note that since we leverage well-known libraries
that the whole Haskell ecosystem uses, there is no risk in using
req. The machinery for performing requests is the same as
with
http-conduit and
wreq. The only difference is
the API.