MyNixOS website logo
Description

An HTTP Client based on Free Monads.

`free-http` is an http-client based on Free Monads. `free-http` exposes a Free Monad to express standard http verbs as well as several backends to interpet programs written in the free monad using various http clients (currently: a pure client, an `http-client`-backed client, and a random client). Please see the ReadMe for usage.

Free Your Client... and Your Requests Will Follow

free-http is an http-client based on Free Monads. free-http exposes a Free Monad to express standard http verbs as well as several backends to interpet programs written in the free monad using various http clients (currently: a pure client, an http-client-backed client, and a random client).

See here for an example.

To use free-http, simply:

  1. Import Network.HTTP.Client.Free to use the library.
  2. Choose your base request type by defining your own instance of the RequestType type family or importing one from an interpreter. E.g.
data MyClient
type instance RequestType MyClient = Request

or

import Network.HTTP.Free.Client.HttpClient (HttpClient)
  1. Choose your base response type by defining your own instance of the ResponseTYpe type family or importing one from an interpreter. E.g.
type instance ResponseType MyClient = Response ByteString

or

import Network.HTTP.Free.Client.HttpClient (HttpClient)
  1. Write a program in the 'FreeHttp MyClient m a' free monad.
  2. Import an interpreter, such as 'HttpClient'
import Network.HTTP.Free.Client.HttpClient
  1. Run your program against the interpreter:
runHttp (myProgram :: FreeHttp MyClient IO String)

Design Choices

RequestType and ResponseType

Haskell is fortunate to have several very well-designed http clients: http-client, wreq, http-conduit, pipes-http, etc. Unfortunately, a few of those clients support several different Request and Response types. To keep free-http flexible, we use two type families defined as:

type family RequestType client  :: *
type family ResponseType client :: *

Our HttpF functor is thus defined as:

data HttpF client a = HttpF StdMethod (RequestType client) (ResponseType client -> a)
                    deriving Functor

This allows our HttpF functor to be agnostic of the foundational request and response type, while allowing interpreter authors to specify the concrete types they need for their http client libraries (e.g. Request in the case of http-client). A consequence of this is that free-http clients (you) need to specify, at some point, the foundation you're using. This can be done in two ways:

  1. You can define your own foundation (see above).
  2. You can import one from an interpreter.

To specify your request and response foundation, use replace the client type in HttpF client a or FreeHttp client m a to the type signalling your foundation. For example, the http-client, pure, and arbitrary interpreters use HttpClient, PureClient, and ArbitraryClient respectively.

Metadata

Version

0.2.0

License

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows