Skip to content

Network Module

The network module provides an interface to the browser's network. This includes making requests, firing pixels, and other network-related tasks.

This module is available directly from the namespace:

var network_module = namespace.network();

Architecture

The network module contains a few core components that its API builds off of.

Firstly, the network module abstracts request types (xhr, beacon, image) from the user so that requests can be made independent from the specifics of each request type.

Looking for functionality?

Currently only HTTP requests are supported by the network module. There are plans to support streaming and websockets already in the works.

Any request can also set the persist flag if you are using image requests, which will add the pixel to a data container in the DOM.

Info

Due to the numerous browser types and web standards, the module has the capabilities() function to provide you which capabilities are available in the current browser.

API

The network API wraps these capabilities in a few simple functions to work with the browser's network.

request

The request method should be used to make a request over the network.

Usage

network_module.request(uri, [params]);

Parameters

Parameter Example Description
uri
'mypixel.com/gif'
The URI the request will be hitting
params
{
method: 'GET',
transport: 'image',
callback: function() {
...
},
persist: true,
query: {
a: 1,
b: '2',
c: true
}
}
the parameters configuring the request

Below are the possible parameters in the params object that augment the request:

Parameter Example Description
method
'GET'
The method of the request, one of:
- GET
- POST
- PATCH
- PUT
- DELETE
- OPTIONS
scheme
'https'
The scheme of the request (default: inherit from page), one of:
- https (default)
- http
transport
'image'
The transport to use, one of:
- xhr (default)
- image
- beacon
callback
function(response) {

}
The callback that is called when the response is recieved
persist
true
The flag to determine if the request will persist in the DOM. Only works for 'image' transport
query
{
key1: value1,
...
}
The query parameters to add to the request
body
{
key1: value1,
...
}
The body of the request (methods: POST, PUT, PATCH)

Last update: 2023-04-13