ActionRouter
Instance member (public) | Purpose | Concept reference |
---|---|---|
use | Registers a middleware function | Read more |
branch | Creates a branch diversion | Read more |
input | Registers a zod schema | Read more |
run | Registers a action handler function | Read more |
ActionHandler params
ActionRequest
object
Prop | Type | Purpose | Initial Value |
---|---|---|---|
context | Initially, { inputs: void } , for rest of the middlewares and action handlers it depends upon chaining flow | Contains context information for each request like inputs and can be extended to inject dependencies like database instance, helper methods, etc | { inputs: null } |
cookies | ReadonlyRequestCookies | Provides request cookies | headers() |
headers | ReadonlyHeaders | Provides request headers | cookies() |
ActionResponse
object
Prop | Type | Purpose |
---|---|---|
data | Function, (data: any) => ({ success: true, data }) | Takes any data and returns a data response object |
error | Function, (code: string, message?: string) => ({ success: false, error: { code, message } }) | Takes error code which is pre-defined in router config and a optional message override to the default message of the error code and returns an error response object. |
createError | Function | Works just like error function but useful when you need to create an inferrable error code just in time |
notFound | Function | Throws notFound error |
redirect | Function | Throws redirect error |