Link Search Menu Expand Document

Http overview

Makes http calls to remote resources as Cmds.

See Http Elm package.

Added in v0.5.0


Table of contents


constructors

get

Signature

export declare function get<A>(url: string, decoder: Decoder<A>): Request<A>

Added in v0.5.0

post

Signature

export declare function post<A>(url: string, body: unknown, decoder: Decoder<A>): Request<A>

Added in v0.5.0

destructors

toTask

Signature

export declare function toTask<A>(req: Request<A>): TaskEither<HttpError, A>

Added in v0.5.0

model

Headers (type alias)

Signature

export type Headers = Record<string, string>

Added in v0.6.0

HttpError (type alias)

Signature

export type HttpError =
  | { readonly _tag: 'BadUrl'; readonly value: string }
  | { readonly _tag: 'Timeout' }
  | { readonly _tag: 'NetworkError'; readonly value: string }
  | { readonly _tag: 'BadStatus'; readonly response: Response<string> }
  | { readonly _tag: 'BadPayload'; readonly value: string; readonly response: Response<string> }

Added in v0.5.0

Method (type alias)

Signature

export type Method = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE'

Added in v0.5.0

Request (interface)

Signature

export interface Request<A> {
  expect: Decoder<A>
  url: string
  method: Method
  headers: Headers
  body?: unknown
  timeout: Option<number>
  withCredentials: boolean
}

Added in v0.5.0

Response (interface)

Signature

export interface Response<Body> {
  url: string
  status: {
    code: number
    message: string
  }
  headers: Headers
  body: Body
}

Added in v0.5.0

utils

send

Executes as Cmd the provided call to remote resource, mapping the result to a Msg.

Derived from sendBy.

Signature

export declare function send<A, Msg>(f: (e: Either<HttpError, A>) => Msg): (req: Request<A>) => Cmd<Msg>

Added in v0.5.0

sendBy

Executes as Cmd the provided call to remote resource, mapping the full Response to a Msg.

Signature

export declare function sendBy<A, Msg>(f: (e: Either<HttpError, Response<A>>) => Msg): (req: Request<A>) => Cmd<Msg>

Added in v0.6.0