This repository was archived by the owner on Aug 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
Groups
Alexander Haslam edited this page Aug 22, 2016
·
6 revisions
The @app.Group
annotation is used to define a group of routes, interceptors and error handlers:
@app.Group("/user")
class UserService {
@app.Route("/find")
findUser(@app.QueryParam("n") String name,
@app.QueryParam("c") String city) {
...
}
@app.Route("/add", methods: const [app.POST])
addUser(@app.Body(app.JSON) Map json) {
...
}
}
The prefix defined with the @app.Group
annotation, will be prepended in every route and interceptor inside the group. If you need to directly bind to the group's path, you can use the @DefaultRoute
annotation:
@app.Group("/user")
class UserService {
@app.DefaultRoute()
getUser() {
...
}
@app.DefaultRoute(methods: const[app.POST])
postUser(@app.Body(app.JSON) Map user) {
...
}
@app.Route("/:id")
getUserById(String id) {
...
}
}
If you wish to create your own custom groups, you can extend the default Group annotation.
class ApiGroup extends app.Group {
const ApiGroup(String urlPrefix) : super("/api" + urlPrefix);
}
@ApiGroup('/todo')
class ApiTodoService {
@app.DefaultRoute()
getTodo() {
// ...
}
}
-
Quick Start Guide
-
Reference
-
Serialization
-
Databases
-
MVC
-
Web Sockets