NestJSNest building blocksLesson 42 / 69

Your first endpoint

Exercise35 min

Your first endpoint

An endpoint is a decorated method:

@Get(':slug/courses/:courseSlug')
getCourse(
  @Param('slug') slug: string,
  @Param('courseSlug') courseSlug: string,
): Promise<CourseDetailDto> {
  return this.roadmaps.getCourse(slug, courseSlug);
}

Run npm run start:dev, open http://localhost:3000/roadmaps/fullstack/courses/web-design, and you see the JSON that every roadmap page in this app renders. One decorator maps the URL, one maps the params, and the return value becomes the response body — that is the whole mechanism.

Exercise

Trace this app's GET /roadmaps/:slug from URL to database and back. Sketch each stop on paper.

Practice in the diagram lab

This lesson's practice belongs in the diagram editor — design the schema you just read about, grade it against the solution, and save it to your account.

Open the diagram lab