@PlainBody
@nestia/core
export function PlainBody(): ParameterDecorator;Parameter decorator for text/plain request bodies. Drop-in replacement for @Body() when the wire format is plain text rather than JSON.
The decorator hands you the raw request body as a string. If the parameter type declares constraints via typia tags, the body is validated against them and a mismatch returns 400 Bad Request.
For JSON bodies use @TypedBody. For form-urlencoded use @TypedQuery.Body. For multipart use @TypedFormData.
Basic usage
src/controllers/WebhooksController.ts
import { PlainBody, TypedRoute } from "@nestia/core";
import { Controller } from "@nestjs/common";
import { tags } from "typia";
@Controller("webhooks")
export class WebhooksController {
// Accept any plain-text body.
@TypedRoute.Post("raw")
public async raw(
@PlainBody() body: string,
): Promise<{ length: number }> {
return { length: body.length };
}
// Constrain the body shape.
@TypedRoute.Post("token")
public async token(
@PlainBody() token: string & tags.Pattern<"^[A-Za-z0-9_-]+$"> & tags.MaxLength<200>,
): Promise<{ ok: true }> {
return { ok: true };
}
}A POST /webhooks/token with body bad!!! returns 400; with body eyJhbGc... it succeeds.
When to use
- Webhooks that POST plain text (Stripe signature blocks, raw payloads).
- Token endpoints that accept a single opaque string.
- Healthcheck-style endpoints that take plain text.
For structured data, prefer @TypedBody() β JSON is easier to evolve.
See also
- TypedBody β JSON bodies.
- TypedQuery.Body β form-urlencoded bodies.
- TypedFormData β multipart bodies (file uploads).
Last updated on