Skip to content

Instantly share code, notes, and snippets.

@MrCube42
Created March 28, 2020 12:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MrCube42/3b4d1e6668d86040468ecfee71aa7712 to your computer and use it in GitHub Desktop.
Save MrCube42/3b4d1e6668d86040468ecfee71aa7712 to your computer and use it in GitHub Desktop.
Implementierung einer POST Route, die über ihren Body das zuvor als TypeScript Klasse definierte Datentransfer-Objekt entgegennimmt.
import { Body, Controller, Post } from '@nestjs/common';
class ContactDto {
readonly myId: string;
readonly contactId: string;
}
@Controller('contact')
export class ContactController {
@Post()
sayHello(@Body() contactDto: ContactDto): string {
const { myId, contactId } = contactDto;
// … Freund mit ID myId sagt ‘Hallo’ zu Freund mit ID contactId
return response;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment