Header menu logo FsHttp

Composability

There are many ways to compose HTTP requests with FsHttp, depending on your needs. A common pattern is to define a base request builder that is then used to create more specific request builders. This is useful when targeting different environments, and don't want to repeat the same configuration for each request.

An example with comments:

open FsHttp.Operators

let httpForMySpecialEnvironment =
    let baseUrl = "http://my-special-environment"
    http {
        // we would like to have a fixed URL prefix for all requests.
        // So we define a new builder that actually uses a base url, like so:
        config_useBaseUrl baseUrl

        // ...in case you need more control, you can also transform the URL:
        config_transformUrl (fun url -> baseUrl </> url)

        // ...or you can transform the header in a similar way.
        // Since the description of method is a special thing,
        // we have to change the URL for any method using a header transformer,
        // like so:
        config_transformHeader (fun (header: Header) ->
            let address = baseUrl </> header.target.address.Value
            { header with target.address = Some address })

        // other header values can be just configured as usual:
        AuthorizationBearer "**************"
    }

let response =
    httpForMySpecialEnvironment {
        GET "/api/v1/users"
    }
    |> Request.sendAsync
namespace FsHttp
module Operators from FsHttp
val httpForMySpecialEnvironment: HeaderContext
val baseUrl: string
Multiple items
static member HttpBuilder.http: HeaderContext

--------------------
property HttpBuilder.http: HeaderContext with get
custom operation: config_useBaseUrl (string) Calls IRequestContext.UseBaseUrl
custom operation: config_transformUrl (string -> string) Calls IRequestContext.TransformUrl
val url: string
custom operation: config_transformHeader (Header -> Header) Calls IRequestContext.TransformHeader
val header: Header
Multiple items
module Header from FsHttp.Dsl

--------------------
type Header = { target: FsHttpTarget headers: Map<string,string> cookies: Cookie list }
val address: string
Header.target: FsHttpTarget
FsHttpTarget.address: string option
property Option.Value: string with get
union case Option.Some: Value: 'T -> Option<'T>
custom operation: AuthorizationBearer (string) Calls IRequestContext.AuthorizationBearer
<summary> Authorization header using Bearer authorization token </summary>
val response: Async<Response>
custom operation: GET (string) Calls IRequestContext.Get
Multiple items
module Request from FsHttp.Print

--------------------
module Request from FsHttp

--------------------
type Request = { header: Header content: BodyContent config: Config printHint: PrintHint }
val sendAsync: request: IToRequest -> Async<Response>
<summary> Sends a request asynchronously. </summary>

Type something to start searching.