Questions & Answers

Can I use controller classes to define http routes?

Deepkit HTTP
50 up-votes
Warning: The answer is generated by an artificial intelligence. It might not be correct.
To adjust rating, open the thread in Discord and click on the up/down vote button.

Yes, controller classes can be used to define http routes. The routes are defined as methods decorated with the appropriate HTTP verb decorators, such as @http.GET or @http.POST. For example:

import { http, HttpRouterRegistry } from '@deepkit/http';

class UserController {
    constructor(private database: Database) {}

    @http.GET('/user/:id')
    getUser(id: number) {
        // Route logic
    }
}

const app = new App({
    controllers: [UserController],
    imports: [new FrameworkModule()]
});