MyNixOS website logo
Description

"HTTP client for haskell, inpired by requests and http-dispatch.".

"HTTP client for haskell, inpired by requests and http-dispatch."

request

HTTP client for haskell, inpired by requests and http-dispatch.

Installation

This pacakge is published on hackage with the same name request, you can install it with cabal or stack or nix as any other hackage packages.

Usage

You can try this in haskell REPL once you have request installed:

import Network.HTTP.Request

resp <- get "https://api.leancloud.cn/1.1/date"
print $ requestStatus resp

Core API

Request's API has three core concepts: Request record type, Response record type, send function.

Request

Request is all about the information you will send to the target URL.

data Request = Request
  { requestMethod  :: Method
  , requestUrl     :: String
  , requestHeaders :: Headers
  , requestBody    :: Maybe Data.ByteString.ByteString
  } deriving (Show)

send

Once you have constructed your own Request record, you can call the send function to send it to the server. The send function's type is:

send :: Request -> IO Response

Response

Response is what you got from the server URL.

data Response = Response
  { responseStatus  :: Int
  , responseHeaders :: Headers
  , responseBody    :: Data.ByteString.ByteString
  } deriving (Show)

Example

:set -XOverloadedStrings

import Network.HTTP.Request

-- Construct a Request record.
let req = Request GET "https://api.leancloud.cn/1.1/date" [] Nothing
-- Send it.
res <- send req
-- access the fields on Response.
print $ requestStatus resp

Shortcuts

As you expected, there are some shortcuts for the most used scenarios.

get :: String -> IO Response
get url =
  send $ Request GET url [] Nothing

delete :: String -> IO Response
delete url =
  send $ Request DELETE url [] Nothing

post :: (String, Maybe Data.ByteString.ByteString) -> IO Response
post (url, body) =
  send $ Request POST url [] body

put :: (String, Maybe Data.ByteString.ByteString) -> IO Response
put (url, body) =
  send $ Request PUT url [] body

These shortcuts' definitions are simple and direct. You are encouraged to add your own if the built-in does not match your use cases, like add custom headers in every request.

API Documents

See the hackage page: http://hackage.haskell.org/package/request/docs/Network-HTTP-Request.html

About the Project

Request is © 2020-2021 by aisk.

License

Request is distributed by a BSD license.

Metadata

Version

0.2.2.0

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