Adds a parameter resolver for parameters based on the class type. Use .resolveParameterByName() for name-based resolving.
class UserResolver {
resolve(context: RouteParameterResolverContext): any | Promise<any> {
return new User();
}
}
class MyController {
@http.GET()
@http.resolveParameter(User, UserResolver)
myAction(user: User) {
}
}
new App({providers: [UserResolver]}).run();
Adds a parameter resolver for parameters based on its name. Use .resolveParameter() for class-based resolving.
class UserResolver {
resolve(context: RouteParameterResolverContext): any | Promise<any> {
return new User();
}
}
class MyController {
@http.GET()
@http.resolveParameterByName('user', UserResolver)
myAction(user: User) {
}
}
new App({providers: [UserResolver]}).run();
Adds additional information about what HTTP status codes are available in this route. You can add additionally a description and a response body type.
The type is used for serialization for responses with the given statusCode.
This information is available in Deepkit API console.
http.GET().response<boolean>(200, 'All ok')
interface User {
username: string;
}
http.GET().response<User>(200, 'User object')
interface HttpErrorMessage {
error: string;
}
http.GET().response<HttpErrorMessage>(500, 'Error')
Optional
type: ReceiveType<T>Allows to change the HttpAction object and composite multiple properties into one function.
const authGroup = Symbol('authGroup');
function authGroup(group: 'admin' | 'user') {
return (action: HttpAction) => {
action.data.set(authGroup, group);
};
}
class My Controller {
@http.GET('/assets').use(authGroup('admin'))
assets() {}
}
Generated using TypeDoc
Arbitrary value container that can be read in RouterParameterResolver and all HTTP workflow events (like authentication).
Example