Set of methods for operating HTTP requests

In an eitri-app, it's important to note that it's only possible to make HTTP requests through these commands. The format is similar to a well-known library called axios.

Hierarchy

  • Http

Methods

  • Performs an HTTP POST request

    Works similarly to axios

    Notes: Only HTTPS requests are accepted

    You can pass an authentication header through the headers field

    Example:

    Eitri.http.post('https://myaddress.com',
    {
    myData: "value of my data"
    },
    {
    "headers": {"Content-Type": "application/json"}
    }
    )

    For streaming responses, use postStream instead.

    Compatibility Control

    • API LEVEL 1 - Functionality added
    • API LEVEL 3 - Adds support for multipart/form-data
    • API LEVEL 12 - Adds support for application/x-www-form-urlencoded

    Parameters

    • url: string

      HTTP address for the request

    • Optional data: any

      Data to be sent

    • Optional config: HttpConfig

      Additional configurations for the request

    Returns Promise<HttpResponse>

  • Performs an HTTP GET request

    Works similarly to axios

    Notes:

    Only HTTPS requests are accepted

    You can pass an authentication header through the headers

    Example:

    Eitri.http.get('https://myaddress.com')
    

    Compatibility Control

    • API LEVEL 1 - Functionality added

    Parameters

    • url: string

      HTTP address for the request

    • Optional config: HttpConfig

      Additional configurations for the request

    Returns Promise<HttpResponse>

  • Performs an HTTP DELETE request

    Works similarly to axios

    Notes: Only HTTPS requests are accepted

    You can pass an authentication header through the headers

    Example:

    Eitri.http.delete('https://myaddress.com', {
    data: { ids: [1, 2, 3] },
    headers: { "Content-Type": "application/json" }
    })

    Compatibility Control

    • API LEVEL 1 - Functionality added

    Parameters

    • url: string

      HTTP address for the request

    • Optional config: HttpDeleteConfig

      Additional configurations for the request. Use config.data to send a request body.

    Returns Promise<HttpResponse>

  • Performs an HTTP PUT request

    Works similarly to axios

    Notes: Only HTTPS requests are accepted

    You can pass an authentication header through the headers

    Example:

    Eitri.http.put('https://myaddress.com',
    {
    myData: "value of my data"
    },
    {
    "headers": {"Content-Type": "application/json"}
    }
    )

    Compatibility Control

    • API LEVEL 1 - Functionality added
    • API LEVEL 3 - Adds support for multipart/form-data
    • API LEVEL 12 - Adds support for application/x-www-form-urlencoded

    Parameters

    • url: string

      HTTP address for the request

    • Optional data: any

      Data to be sent

    • Optional config: HttpConfig

      Additional configurations for the request

    Returns Promise<HttpResponse>

  • Performs an HTTP PATCH request

    Works similarly to axios

    Notes: Only HTTPS requests are accepted

    You can pass an authentication header through the headers

    Example:

    Eitri.http.patch('https://myaddress.com',
    {
    myData: "value of my data"
    },
    {
    "headers": {"Content-Type": "application/json"}
    }
    )

    Compatibility Control

    • API LEVEL 1 - Functionality added
    • API LEVEL 3 - Adds support for multipart/form-data
    • API LEVEL 12 - Adds support for application/x-www-form-urlencoded

    Parameters

    • url: string

      HTTP address for the request

    • Optional data: any

      Data to be sent

    • Optional config: HttpConfig

      Additional configurations for the request

    Returns Promise<HttpResponse>

  • Performs an HTTP HEAD request

    Works similarly to axios

    Notes: Only HTTPS requests are accepted

    You can pass an authentication header through the headers

    Example:

    Eitri.http.head('https://myaddress.com', {"headers": {"Content-Type": "application/json"}})
    

    Compatibility Control

    • API LEVEL 1 - Functionality added

    Parameters

    • url: string

      HTTP address for the request

    • Optional config: HttpConfig

      Additional configurations for the request

    Returns Promise<HttpResponse>

  • Performs an HTTP OPTIONS request

    Works similarly to axios

    Notes: Only HTTPS requests are accepted

    You can pass an authentication header through the headers

    Example:

    Eitri.http.options('https://myaddress.com', { "headers": { "Content-Type": "application/json" } } )
    

    Compatibility Control

    • API LEVEL 1 - Functionality added

    Parameters

    • url: string

      HTTP address for the request

    • Optional config: HttpConfig

      Additional configurations for the request

    Returns Promise<HttpResponse>

  • Performs a general purpose HTTP request using Axios syntax

    Works similarly to axios

    Notes: Only HTTPS requests are accepted

    Example:

    const requestConfig = {
    url: "https://myaddress.com",
    method: "POST",
    headers: { "Content-Type": "application/json" },
    timeout: 5000,
    data: { foo: "bar"},
    }

    Eitri.http.request(requestConfig)

    Compatibility Control

    • API LEVEL 1 - Functionality added

    Parameters

    Returns Promise<HttpResponse>

  • Performs a streaming HTTP POST request. Returns an HttpStreamResponse with a dataChannel for EventBus subscription.

    After calling this method, subscribe to the EventBus with the returned dataChannel, then call startStream to begin receiving chunks.

    Example:

    const stream = await Eitri.http.postStream(
    'https://api.example.com/chat/completions',
    { prompt: "Hello" },
    { headers: { "Content-Type": "application/json" } }
    )

    Eitri.eventBus.subscribe({
    channel: stream.dataChannel,
    callback: async (chunk) => {
    if (chunk.success && chunk.data) {
    console.log("Received:", chunk.data.text)
    }
    if (chunk.final) {
    await Eitri.http.cancelStream({ dataChannel: stream.dataChannel })
    }
    }
    })

    await Eitri.http.startStream({ dataChannel: stream.dataChannel })

    Compatibility Control

    • API LEVEL 34 - Functionality added

    Parameters

    • url: string

      HTTP address for the request

    • Optional data: any

      Data to be sent

    • Optional config: HttpConfig

      Additional configurations for the request

    Returns Promise<HttpStreamResponse>

  • Performs a streaming HTTP GET request. Returns an HttpStreamResponse with a dataChannel for EventBus subscription.

    After calling this method, subscribe to the EventBus with the returned dataChannel, then call startStream to begin receiving chunks.

    Example:

    const stream = await Eitri.http.getStream('https://api.example.com/stream/data')

    Eitri.eventBus.subscribe({
    channel: stream.dataChannel,
    callback: async (chunk) => {
    if (chunk.success && chunk.data) {
    console.log("Received:", chunk.data.text)
    }
    if (chunk.final) {
    await Eitri.http.cancelStream({ dataChannel: stream.dataChannel })
    }
    }
    })

    await Eitri.http.startStream({ dataChannel: stream.dataChannel })

    Compatibility Control

    • API LEVEL 34 - Functionality added

    Parameters

    • url: string

      HTTP address for the request

    • Optional config: HttpConfig

      Additional configurations for the request

    Returns Promise<HttpStreamResponse>

  • Performs a streaming HTTP DELETE request. Returns an HttpStreamResponse with a dataChannel for EventBus subscription.

    After calling this method, subscribe to the EventBus with the returned dataChannel, then call startStream to begin receiving chunks. See getStream for a full usage example.

    Compatibility Control

    • API LEVEL 34 - Functionality added

    Parameters

    • url: string

      HTTP address for the request

    • Optional config: HttpDeleteConfig

      Additional configurations for the request. Use config.data to send a request body.

    Returns Promise<HttpStreamResponse>

  • Performs a streaming HTTP PUT request. Returns an HttpStreamResponse with a dataChannel for EventBus subscription.

    After calling this method, subscribe to the EventBus with the returned dataChannel, then call startStream to begin receiving chunks. See postStream for a full usage example.

    Compatibility Control

    • API LEVEL 34 - Functionality added

    Parameters

    • url: string

      HTTP address for the request

    • Optional data: any

      Data to be sent

    • Optional config: HttpConfig

      Additional configurations for the request

    Returns Promise<HttpStreamResponse>

  • Performs a streaming HTTP PATCH request. Returns an HttpStreamResponse with a dataChannel for EventBus subscription.

    After calling this method, subscribe to the EventBus with the returned dataChannel, then call startStream to begin receiving chunks. See postStream for a full usage example.

    Compatibility Control

    • API LEVEL 34 - Functionality added

    Parameters

    • url: string

      HTTP address for the request

    • Optional data: any

      Data to be sent

    • Optional config: HttpConfig

      Additional configurations for the request

    Returns Promise<HttpStreamResponse>

  • Performs a streaming HTTP HEAD request. Returns an HttpStreamResponse with a dataChannel for EventBus subscription.

    After calling this method, subscribe to the EventBus with the returned dataChannel, then call startStream to begin receiving chunks. See getStream for a full usage example.

    Compatibility Control

    • API LEVEL 34 - Functionality added

    Parameters

    • url: string

      HTTP address for the request

    • Optional config: HttpConfig

      Additional configurations for the request

    Returns Promise<HttpStreamResponse>

  • Performs a streaming HTTP OPTIONS request. Returns an HttpStreamResponse with a dataChannel for EventBus subscription.

    After calling this method, subscribe to the EventBus with the returned dataChannel, then call startStream to begin receiving chunks. See getStream for a full usage example.

    Compatibility Control

    • API LEVEL 34 - Functionality added

    Parameters

    • url: string

      HTTP address for the request

    • Optional config: HttpConfig

      Additional configurations for the request

    Returns Promise<HttpStreamResponse>

  • Cancels an active HTTP stream by its dataChannel identifier. Stops the native-side byte reading and releases the HTTP connection.

    Example:

    await Eitri.http.cancelStream({ dataChannel: stream.dataChannel })
    

    Compatibility Control

    • API LEVEL 34 - Functionality added

    Parameters

    • dataChannel: {
          dataChannel: string;
      }

      The dataChannel returned by a stream method

      • dataChannel: string

    Returns Promise<void>

  • Signals the native side to start streaming data for a previously opened stream. Must be called AFTER subscribing to the EventBus with the stream's dataChannel.

    This is required to avoid a race condition where native starts sending chunks before the eitri-app has registered its callback.

    Example:

    // 1. Open the stream (native connects but pauses before reading body)
    const stream = await Eitri.http.getStream('https://api.example.com/events')

    // 2. Subscribe to the data channel
    Eitri.eventBus.subscribe({
    channel: stream.dataChannel,
    callback: async (chunk) => {
    if (chunk.success && chunk.data) {
    console.log("Chunk:", chunk.data.text)
    }
    if (chunk.final) {
    await Eitri.http.cancelStream({ dataChannel: stream.dataChannel })
    }
    }
    })

    // 3. Signal native to start streaming (safe — listener is already registered)
    await Eitri.http.startStream({ dataChannel: stream.dataChannel })

    Compatibility Control

    • API LEVEL 34 - Functionality added

    Parameters

    • dataChannel: {
          dataChannel: string;
      }

      The dataChannel returned by a stream method

      • dataChannel: string

    Returns Promise<void>

  • Performs a general purpose streaming HTTP request using Axios syntax. Dispatches to the appropriate HTTP streaming method based on config.method (GET, POST, PUT, etc..).

    After calling this method, subscribe to the EventBus with the returned dataChannel, then call startStream to begin receiving chunks.

    Example:

    const stream = await Eitri.http.requestStream({
    url: 'https://api.example.com/chat/completions',
    method: 'POST',
    data: { prompt: "Hello" },
    headers: { "Content-Type": "application/json" },
    timeout: 30000,
    })

    Eitri.eventBus.subscribe({
    channel: stream.dataChannel,
    callback: async (chunk) => {
    if (chunk.success && chunk.data) {
    console.log("Received:", chunk.data.text)
    }
    if (chunk.final) {
    await Eitri.http.cancelStream({ dataChannel: stream.dataChannel })
    }
    }
    })

    await Eitri.http.startStream({ dataChannel: stream.dataChannel })

    Compatibility Control

    • API LEVEL 34 - Functionality added

    Parameters

    Returns Promise<HttpStreamResponse>

  • Downloads a file using HTTP and stores it on the device.

    Allowed Extensions:

    [
    "txt", // Plain Text
    "rtf", // Rich Text Format
    "pdf", // PDF - Portable Document Format
    "md", // Markdown
    "xls", "xlsx", // Microsoft Excel
    "csv", // CSV - Comma-Separated Values
    "gsheet", // Google Sheets
    "ppt", "pptx", // Microsoft PowerPoint
    "doc", "docx", // Microsoft Word
    "gdoc", // Google Docs
    "jpg", "jpeg", // JPEG Image
    "png", // PNG Image
    "gif", // GIF Image
    "mp3", // MP3 Audio
    "wav", // WAV Audio
    "mp4", // MP4 Video
    "avi", // AVI Video
    "zip", // ZIP Archive
    "rar", // RAR Archive
    "epub", // EPUB Ebook
    "mobi", // Kindle Ebook
    "key", // Adobe Acrobat Keynote (for Apple Keynote presentations)
    "pages", // Apple Pages
    "numbers", // Apple Numbers
    "keynote" // Apple Keynote
    ]

    Example:

    await Eitri.fs.download({
    url: "https://domain.com/file-to-download",
    fileName: "invoice-02-2023.pdf",
    })

    Compatibility Control

    • API LEVEL 4 - Functionality added

    Parameters

    Returns Promise<EitriFile>

  • Uploads a file to a server using HTTP.

    Example:


    let files = await Eitri.fs.openImagePicker({
    fileExtension: ["jpg", "png"],
    allowsMultipleSelection: false
    });

    if(files.length > 0){
    let file = files[0]

    // raw upload
    await Eitri.http.upload({
    url: "https://domain.com/upload",
    method: "POST",
    file: file,
    config: {
    headers: {
    "Content-Type": file.mimeType
    }
    }
    });

    // multipart/form-data upload
    await Eitri.http.upload({
    url: "https://domain.com/upload",
    method: "POST",
    multipartData: [
    {field: "firstName", value: "Upload"},
    {field: "lastName", value: "Test"},
    {field: "file", file: file}
    ],
    config: {
    headers: {
    "AAA": "BBB"
    }
    }
    });

    }

    Compatibility Control

    • API LEVEL 24 - Functionality added

    Parameters

    Returns Promise<HttpResponse>

  • Performs a general purpose HTTP request using fetch syntax

    Works similarly to fetch

    Notes:

    Only HTTPS requests are accepted

    Signals are not supported, use timeout property

    Example:

    Eitri.http.fetch("https://myaddress.com", {
    method: "POST",
    body: { foo: "bar"},
    timeout: 1000 * 5,
    })

    Compatibility Control

    • API LEVEL 1 - Functionality added

    Parameters

    Returns Promise<FetchResponse>

Generated using TypeDoc