Adapter
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 { WebsocketAdapter } from "@hyper-fetch/sockets"
import { WebsocketAdapter } from "@hyper-fetch/sockets";
const socket = new Socket({
url: "http://localhost:3000",
adapter: WebsocketAdapter(),
});
Server Sent Events (SSE) Adapter
The ServerSentEventsAdapter
is used to communicate with the Server Sent Events (SSE)
server.
import { ServerSentEventsAdapter } from "@hyper-fetch/sockets"
import { ServerSentEventsAdapter } from "@hyper-fetch/sockets";
const socket = new Socket({
url: "http://localhost:3000",
adapter: ServerSentEventsAdapter(),
});
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
.