Module http

Description

The http module in Active-Connect provides an HTTP server and all the necessary utilities to configure it. With this module, developers can easily create custom HTTP endpoints, handle incoming requests, and send appropriate responses.

Developers can use the provided decorators, such as @GET, @POST, @PUT, and others, along with their respective handler methods, to define the functionality for each HTTP verb.

Additionally, this module supports optional WebSocket mode, which allows real-time communication when starting the server. Further details about WebSocket can be found within the websocket section.

Setup Instructions

Step 1: Import the required classes and create an HTTP server object using HttpServer.

import { GET, HttpServer, HttpRequest, HttpResponse } from 'active-connect';

Step 2: Define HTTP methods (e.g., GET, POST) within your service classes using decorators.

class ExampleHttpService {
@GET("/example")
async getExample(request: HttpRequest): Promise<HttpResponse> {
return {
content: "...",
contentType: "text/plain",
status: 200,
contentEncoding: "binary", // supports "base64"
};
}
}

Step 3: Load files containing HTTP methods within the entry point file of your application.

Step 4: Start the HTTP server.

const server = new HttpServer(80, false); // Set 'true' to enable WebSocket support

Index

Classes

Interfaces

Functions

Generated using TypeDoc