Javascript SDK
Reference
validatePayloadOrThrow

validatePayloadOrThrow

Validate the incoming payload and obtain a typed copy. If the payload is invalid, an error will be thrown. The method is available both as a static and as an instance method.

Parameters

  • body: unknown - The incoming request body.

Returns

  • LlamaWsIncomingRequestPayload | Error - The typed payload.

Example

import { LlamaWorkspace } from "llamaworkspace";
 
// app is an instance of express, koa, hono or any other web framework
app.post("/", async (req) => {
  const body = await req.body();
  const typedBody = LlamaWorkspace.validatePayloadOrThrow(body);
 
  // Use "data" to process the request
  const { data } = typedBody;
});