Class MatrixHttpApi<O>

Type Parameters

Hierarchy

Constructors

Properties

opts: O
uploads: Upload[] = []

Methods

  • Perform an authorised request to the homeserver.

    Returns

    Promise which resolves to

    {
    data: {Object},
    headers: {Object},
    code: {Number},
    }

    If onlyData is set, this will resolve to the data object only.

    Returns

    Rejects with an error if a problem occurred. This includes network problems and Matrix-specific error JSON.

    Type Parameters

    • T

    Parameters

    • method: Method

      The HTTP method e.g. "GET".

    • path: string

      The HTTP path after the supplied prefix e.g. "/createRoom".

    • Optional queryParams: QueryDict

      A dict of query params (these will NOT be urlencoded). If unspecified, there will be no query params.

    • Optional body: Body

      The HTTP JSON body.

    • opts: IRequestOpts = {}

      additional options. If a number is specified, this is treated as opts.localTimeoutMs.

    Returns Promise<ResponseType<T, O>>

  • Get the content repository url with query parameters.

    Returns

    An object with a 'base', 'path' and 'params' for base URL, path and query parameters respectively.

    Returns IContentUri

  • Form and return a homeserver request URL based on the given path params and prefix.

    Returns

    URL

    Parameters

    • path: string

      The HTTP path after the supplied prefix e.g. "/createRoom".

    • Optional queryParams: QueryDict

      A dict of query params (these will NOT be urlencoded).

    • Optional prefix: string

      The full prefix to use e.g. "/_matrix/client/v2_alpha", defaulting to this.opts.prefix.

    • Optional baseUrl: string

      The baseUrl to use e.g. "https://matrix.org/", defaulting to this.opts.baseUrl.

    Returns URL

  • Perform a request to the homeserver without any credentials.

    Returns

    Promise which resolves to

    {
    data: {Object},
    headers: {Object},
    code: {Number},
    }

    If onlyData</code> is set, this will resolve to the <code>data object only.

    Returns

    Rejects with an error if a problem occurred. This includes network problems and Matrix-specific error JSON.

    Type Parameters

    • T

    Parameters

    • method: Method

      The HTTP method e.g. "GET".

    • path: string

      The HTTP path after the supplied prefix e.g. "/createRoom".

    • Optional queryParams: QueryDict

      A dict of query params (these will NOT be urlencoded). If unspecified, there will be no query params.

    • Optional body: Body

      The HTTP JSON body.

    • Optional opts: IRequestOpts

      additional options

    Returns Promise<ResponseType<T, O>>

  • Perform a request to an arbitrary URL.

    Returns

    Promise which resolves to data unless onlyData is specified as false, where the resolved value will be a fetch Response object.

    Returns

    Rejects with an error if a problem occurred. This includes network problems and Matrix-specific error JSON.

    Type Parameters

    • T

    Parameters

    • method: Method

      The HTTP method e.g. "GET".

    • url: string | URL

      The HTTP URL object.

    • Optional body: Body

      The HTTP JSON body.

    • opts: Pick<IRequestOpts, "json" | "headers" | "localTimeoutMs" | "keepAlive" | "abortSignal"> = {}

      additional options

    Returns Promise<ResponseType<T, O>>

  • Upload content to the homeserver

    Returns

    Promise which resolves to response object, as determined by this.opts.onlyData, opts.rawResponse, and opts.onlyContentUri. Rejects with an error (usually a MatrixError).

    Parameters

    • file: XMLHttpRequestBodyInit

      The object to upload. On a browser, something that can be sent to XMLHttpRequest.send (typically a File). Under node.js, a Buffer, String or ReadStream.

    • opts: UploadOpts = {}

      options object

    Returns Promise<UploadResponse>

Generated using TypeDoc