# Create your first controller

Create a new CalendarCtrl.ts in your controllers directory (by default root/controllers). All controllers declared with IChildrenController decorators are considered as Platform routers (Express.Router, Koa.Router, ...). A Platform router requires a path (here, the path is /calendars) to expose an url on your server. More precisely, it's a part of a path, and the entire exposed url depends on the Server configuration (see Configuration) and the children controllers.

In this case, we have no dependencies and the root endpoint is set to /rest. So the controller's url will be http://host/rest/calendars.

import {Controller, Get} from "@tsed/common";

@Controller("/calendars")
export class CalendarCtrl {
  @Get()
  findAll(): string {
    return "This action returns all calendars";
  }
}
1
2
3
4
5
6
7
8
9

TIP

Decorators getDecoratorType , PostHook , Delete , Input , etc., support dynamic pathParams (eg: /:id) and RegExp like Express API.

See Controllers section for more details

WARNING

You have to configure engine rendering if you want to use the decorator TemplateRenderError .

To test your method, just run your server.ts and send an HTTP request on /rest/calendars/1.

# Ready for More?

We’ve briefly introduced the most basic features of Ts.ED - the rest of this guide will cover them and other advanced features with much finer details, so make sure to read through it all!

Last Updated: 11/30/2020, 6:53:43 PM

Other topics