Iskra API Reference
    Preparing search index...

    Function validateJson

    • Middleware that validates a request's route params, query and/or body against JSON Schemas (AJV, with ajv-formats and ajv-errors). On failure it answers status (400) with the errors by field; on success the handler reads the data from c.get("validated"). A JSON Schema does not carry a TypeScript type, so give the validated shapes as type parameters:

      app.post("/users", validateJson<{ name: string }>({ body: userSchema }), (c) => {
      const { name } = c.get("validated").body;
      });

      Type Parameters

      • Body = unknown
      • Query = unknown
      • Params = unknown

      Parameters

      Returns MiddlewareHandler<
          { Variables: { validated: JsonValidated<Body, Query, Params> } },
      >