Options
All
  • Public
  • Public/Protected
  • All
Menu

Utility to make strongly typed HTTP requests. Uses the Fetch API.

Hierarchy

  • HttpUtil

Index

Methods

Methods

Static get

  • get<T>(path: string, args?: RequestInit): Promise<HttpResponse<T>>
  • Make a strongly typed http GET request.

    example

    const response = await HttpUtil.get<{ id: number }>( "https://jsonplaceholder.typicode.com/posts" );

    Type parameters

    • T

    Parameters

    • path: string

      url for the request

    • Default value args: RequestInit = { method: 'get' }

      fetch API args, defaults to { method: 'get' }

    Returns Promise<HttpResponse<T>>

    a typed async http reponse

Static post

  • post<T>(path: string, body: any, args?: RequestInit): Promise<HttpResponse<T>>
  • Make a strongly typed http POST request.

    example

    const response = await HttpUtil.post<{ id: number }>( "https://jsonplaceholder.typicode.com/posts", { title: "my post", body: "some content" } );

    Type parameters

    • T

    Parameters

    • path: string

      url for the request

    • body: any

      request's body

    • Default value args: RequestInit = { method: 'post', body: JSON.stringify(body) }

      fetch API args, defaults to { method: 'post', body: JSON.stringify(body) }

    Returns Promise<HttpResponse<T>>

    a typed async http reponse

Static put

  • put<T>(path: string, body: any, args?: RequestInit): Promise<HttpResponse<T>>
  • Make a strongly typed http PUT request.

    example

    const response = await HttpUtil.put<{ id: number }>( "https://jsonplaceholder.typicode.com/posts", { title: "my post", body: "some content" } );

    Type parameters

    • T

    Parameters

    • path: string

      url for the request

    • body: any

      request's body

    • Default value args: RequestInit = { method: 'put', body: JSON.stringify(body) }

      fetch API args, defaults to { method: 'put', body: JSON.stringify(body) }

    Returns Promise<HttpResponse<T>>

    a typed async http reponse

Static request

Legend

  • Constructor
  • Property
  • Method
  • Property
  • Method
  • Inherited property
  • Inherited method
  • Protected property
  • Protected method
  • Private property
  • Static method

Generated using TypeDoc