Iskra API Reference
    Preparing search index...

    Function validate

    • Middleware that validates a request's route params, query and/or body with Zod. On failure it answers status (400) with the failed fields in details, by the response contract; malformed JSON is a 400 and a body that is neither JSON nor a form a 415. On success the handler reads the parsed data, typed, from c.get("validated"):

      app.post("/users", validate({ body: z.object({ name: z.string() }) }), (c) => {
      const { name } = c.get("validated").body; // string
      });

      A query field declared as an array takes every value of a repeated parameter (?id=1&id=2); the others take the first.

      Type Parameters

      Parameters

      Returns MiddlewareHandler<{ Variables: { validated: Validated<S> } }>