# Create your first controller
Create a new CalendarCtrl.ts
in your controllers directory (by default root/controllers
).
All controllers declared with
Controller
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 {Get} from "@tsed/schema";
import {Controller} from "@tsed/di";
@Controller("/calendars")
export class CalendarCtrl {
@Get()
findAll(): string {
return "This action returns all calendars";
}
}
2
3
4
5
6
7
8
9
10
TIP
Decorators
Get
,
Post
,
Delete
,
Put
, 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 Render .
The CalendarCtrl
you just added needs to be connected by exporting it. Find a index.ts
in my case in the /rest/
folder and add the following line:
export * from "./CalendarCtrl";
To test your method, just run your server.ts
and send an HTTP request on /rest/calendars/
.
# 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: 10/24/2024, 6:33:40 AM
Other topics
- Session & cookies
- Passport.js
- Keycloak
- Prisma
- TypeORM
- MikroORM
- Mongoose
- GraphQL
- GraphQL WS
- Apollo
- TypeGraphQL
- GraphQL Nexus
- Socket.io
- Swagger
- AJV
- Multer
- Serve static files
- Templating
- Serverless HTTP
- Seq
- OIDC
- Stripe
- Agenda
- Terminus
- Serverless
- Server-sent events
- IORedis
- Vike
- Jest
- Vitest
- Controllers
- Providers
- Model
- JsonMapper
- Middlewares
- Pipes
- Interceptors
- Authentication
- Hooks
- Exceptions
- Throw HTTP Exceptions
- Cache
- Command
- Response Filter
- Injection scopes
- Custom providers
- Lazy-loading provider
- Custom endpoint decorator
- Testing
- Customize 404