Routing
Routes can be found in lib/routes folder. And api.dart is with prefix /api.
Supported routes
Info
Other supported routes are COPY, HEAD, OPTIONS, LINK, UNLINK, PURGE, LOCK, UNLOCK and VIEW.
Param route
Catch-all param
{name*} matches the rest of the path, with slashes.
Route.get('/docs/{page*}', (DoxRequest req, String page) {
return page; // GET /docs/a/b/c gives 'a/b/c'
});
Serve storage files
Route.files(path) serves files of a storage disk at GET <path>/{key*}. By default only signed URLs work.
See File Storage.
Request body for the docs
post, put and patch take a body: schema. It shows in the OpenAPI docs. It does not validate.
Route.post('/posts', controller.store, body: v.object(<String, Schema<Object?>>{
'title': v.string().min(3),
}));
Group Routes
Resource
Info
index, create, store, show, edit, update and destroy are controller methods.
Check here documentation for generating resource controller.
Route with callback
Route with controller
Class based middleware
Info
To implement class-based middleware, you can create a new class that extends the DoxMiddleware class. Within this new class, you'll need to define a handle method where you can incorporate your custom logic.
Function middleware
Info
To create function-based middleware, you can define a function that takes a DoxRequest parameter.