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
COPYCopy the resource
DELETEDelete the resource
GETGet the resource content
HEADGet request headers
LOCKLock the resource
MKCOLCreate resource collection
MOVEMove the resource
OPTIONSGet server options
POSTPost a resource
PROPFINDFind resource property
PROPPATCHEdit resource property
PATCHUpdate the resource partially
PUTUpdate the resource
TRACEPerform a trace call
UNLOCKUnlock 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();
}