![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
@dcos/connections
Advanced tools
👩🔬 Please be aware that this package is still experimental — changes to the interface and underlying implementation are likely, and future development or maintenance is not guaranteed.
This package provides different connection types with a unified interface.
The following example will create an XHRConnection
, add a complete event
listener and open the connection. The complete listener will get called once
the JSON file is loaded and the connection is closed.
import { XHRConnection, ConnectionEvent } from "@dcos/connections";
const connection = new XHRConnection("http://example.com/file.json");
connection.addListener(ConnectionEvent.COMPLETE, (event) => console.log(event));
connection.open();
The AbstractConnection
provides the default properties, methods, states, and
event-definitions to implement a custom connection.
The ConnectionEvent
provides a common interface for all different event types.
Use the following event types...
OPEN
when opening the connectionDATA
every time data is received from the serverERROR
when an error occurredCOMPLETE
when the connection closes without any errorsABORT
when the connection was aborted by somethingThe event target
always points to the connection.
The XHRConnection
wraps the native XMLHttpRequest
to provide a unified and
easy to use interface.
The following example will create an XHRConnection
to post "data" to an
API server.
const connection = new XHRConnection("http://example.com/api", {
method: "POST",
body: "data"
});
connection.open();
This defines the resource location that you want to connect to.
An optional object containing custom settings that you want to apply to the connection.
headers
: Any headers you want to add to your requestmethod
: The request method (default: "GET"
)body
: Any data you want send with your requestresponseType
: The response type you expect (default: "json"
) If the server returns data that is not compatible the value of response
will be null
.Value | Data type of response property |
---|---|
"arraybuffer" | ArrayBuffer |
"blob" | Blob |
"document" | Document |
"json" | JavaScript object, parsed from a JSON string returned by the server |
"text" | DOMString |
FAQs
Provides different connection types with a unified interface
We found that @dcos/connections demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 13 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.