Skip to main content
Version: v7.0.0

Adapter

Read the API Reference »

Adapter is a class that specify the way how to communicate with the server. It defines the way how to send and receive data, how to handle errors, how to handle reconnects, etc. Currently supporting connection types like Websocket, Server Sent Events (SSE) or integrations like Firebase Realtime Database.


Built in Adapters

There are two built in adapters - WebsocketAdapter and ServerSentEventsAdapter providing basic functionality for the Websocket and Server Sent Events (SSE) connection types.


Websocket Adapter

The default adapter is used to communicate with the Websocket server.

Import
import { WebsocketAdapter } from "@hyper-fetch/sockets"

import { WebsocketAdapter } from "@hyper-fetch/sockets";

const socket = new Socket({
url: "http://localhost:3000",
adapter: WebsocketAdapter(),
});
WebsocketAdapter
Read the API Reference for the WebsocketAdapter class.

Server Sent Events (SSE) Adapter

The ServerSentEventsAdapter is used to communicate with the Server Sent Events (SSE) server.

Import
import { ServerSentEventsAdapter } from "@hyper-fetch/sockets"

import { ServerSentEventsAdapter } from "@hyper-fetch/sockets";

const socket = new Socket({
url: "http://localhost:3000",
adapter: ServerSentEventsAdapter(),
});
ServerSentEventsAdapter
Read the API Reference for the ServerSentEventsAdapter class.

Custom Adapter

There is nothing to prevent you from changing this and creating the adapter you need. Thanks to event communication, you can set your own adapter as you wish by only fulfilling the typescript requirements. This way you can create your own adapters for existing libraries like socket.io.


See More

Socket
Learn more about the Socket class and its configuration options.
Emitter
Learn more about the Emitter class and its configuration options.
Listener
Learn more about the Listener class and its configuration options.
Firebase Realtime Database
Learn more about the Firebase Realtime Database integration.