httpland / http-websocket

HTTP request for websocket with standard Request and Response

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

websocket-handler

WebSocket handler implementation and other utilities for working with status codes.

What

This is the WebSocket handler framework. It handles HTTP Request validation and error handling, which you must do when you create a WebSocket Server.

You can concentrate only on WebSocket behavior.

Features

  • Validation for HTTP request what upgrade to WebSocket.
  • Tiny, minimum interface.

Quick View

import {
  createHandler,
  SocketHandler,
} from "https://deno.land/x/ws_handler@$VERSION/mod.ts";
import { serve } from "https://deno.land/std@$VERSION/http/mod.ts";
const socketHandler: SocketHandler = (socket) => {
  socket.onopen = () => {
    socket.send("hello");
  };
};
const handler = createHandler(socketHandler);
serve(handler);

API

createHandler

Create WebSocket request handler.

Example

import {
  createHandler,
  SocketHandler,
} from "https://deno.land/x/ws_handler@$VERSION/mod.ts";
const socketHandler: SocketHandler = (socket) => {
  socket.onopen = () => {
    socket.send("hello");
  };
};
const handler = createHandler(socketHandler);

License

Copyright © 2022-present TomokiMiyauci.

Released under the MIT license

About

HTTP request for websocket with standard Request and Response

License:MIT License


Languages

Language:TypeScript 100.0%