Requests

Entropy provides a fluent API for dealing with web requests. The framework provides several ways to return responses. Each client request is represented by Request object.

Request Object

In order to get access to the request object, you need to explicitly define route request param of type Request:

      

src/users/user.controller.ts

import { HttpRequest } from '@entropy/http'; import { Controller, Route } from '@entropy/router'; export class UserController extends Controller { @Route.Get('/users') public index([], request: HttpRequest) { return this.render('users/index', { path: request.path(), }); } }

HTTP Methods

Entropy recognizes basically all available HTTP verbs / methods:

HTTP method
Description
COPY
Copy the resource
DELETE
Delete the resource
GET
Get the resource content
HEAD
Get request headers
LOCK
Lock the resource
MKCOL
Create resource collection
MOVE
Move the resource
OPTIONS
Get server options
POST
Post a resource
PROPFIND
Find resource property
PROPPATCH
Edit resource property
PATCH
Update the resource partially
PUT
Update the resource
TRACE
Perform a trace call
UNLOCK
Unlock the resource
      

src/chats/chat.controller.ts

import { Module } from '@entropy/server'; import { ChatChannel } from './chat.channel.ts'; import { ChatController } from './chat.controller.ts'; export class ChatModule implements Module { public readonly channels = [ ChatChannel, ]; public readonly controllers = [ ChatController, ]; }

Registering Modules

Every module should be registered in the src/main.ts file in modules section like so:

      

src/main.ts

import { createServer } from '@entropy/server'; import { RootModule } from './root.module.ts'; if (import.meta.main) { const server = await createServer({ modules: [RootModule], }); await server.start(); }
Controllers and Routes Forms