Function: DELETE()
Call Signature
DELETE<
ClassPrototype,Method>(r):MethodDecorator<ClassPrototype,Method,ControllerProperty<ClassPrototype>>
Expose the controller method as an HTTP DELETE action on a route, to delete a resource: the shorthand of @HTTPAction(route, 'delete', …). The adapter assembles the input: by default, the query string merged with the parsed body (JSON; URL encoded with Express), then the route parameters over them. The middlewares run, the input is validated against the DTO (the defaults applied, the unknown keys removed; without a DTO, it is accepted as it is), the access control runs when acl is set, then the method receives the validated input as a plain object. The query values and the route parameters are strings and the DTO schemas are strict: convert them with .strict(false). The value returned is answered by the adapter's responder: as JSON by default, with the status 204 for undefined; Result.status() sets a status and headers. An error thrown is answered as {errno, errMsg} with the first 4xx statusCode along its causes (400 for an invalid input), else its own statusCode, else 500.
Type Parameters
ClassPrototype
ClassPrototype extends Controller
Method
Method
Parameters
r
string
The route, in the syntax of the HTTP adapter (/users/:id); the controller's @Prefix({route}) is prepended to it.
Returns
MethodDecorator<ClassPrototype, Method, ControllerProperty<ClassPrototype>>
The method decorator.
Example
import {DTO} from 'lakutata'
import {Controller} from 'lakutata/com/entrypoint'
import {DELETE} from 'lakutata/decorator/ctrl'
import {Expect} from 'lakutata/decorator/dto'
class SessionIdDTO extends DTO {
@Expect(DTO.String().uuid().required())
public id!: string
}
class SessionController extends Controller {
//DELETE /sessions/<uuid>: answered with the status 204 (no content), an invalid id with the status 400
@DELETE('/sessions/:id', SessionIdDTO, {acl: true})
public async revoke(input: SessionIdDTO): Promise<void> {
console.log(`revoke ${input.id}`)
}
}Call Signature
DELETE<
ClassPrototype,Method,DTOConstructor>(r,dtoConstructor):MethodDecorator<ClassPrototype,Method,ControllerProperty<ClassPrototype>>
Expose the controller method as an HTTP DELETE action on a route, its input validated against a DTO: the shorthand of @HTTPAction(route, 'delete', …). The input is the query string merged with the parsed body, then the route parameters over them (the default of the adapters); the method receives it validated, as a plain object. The value returned is answered as JSON (204 for undefined), an error as {errno, errMsg} with its status (400 for an invalid input, else 500 by default).
Type Parameters
ClassPrototype
ClassPrototype extends Controller
Method
Method
DTOConstructor
DTOConstructor extends typeof DTO = typeof DTO
Parameters
r
string
The route, in the syntax of the HTTP adapter (/users/:id); the controller's @Prefix({route}) is prepended to it.
dtoConstructor
DTOConstructor
The DTO class validating the input; the query values and the route parameters are strings, convert them with .strict(false).
Returns
MethodDecorator<ClassPrototype, Method, ControllerProperty<ClassPrototype>>
The method decorator.
Call Signature
DELETE<
ClassPrototype,Method>(r,actionOptions):MethodDecorator<ClassPrototype,Method,ControllerProperty<ClassPrototype>>
Expose the controller method as an HTTP DELETE action on a route, with action options: the shorthand of @HTTPAction(route, 'delete', …). The input is the query string merged with the parsed body, then the route parameters over them (the default of the adapters), accepted as it is. The value returned is answered as JSON (204 for undefined), an error as {errno, errMsg} with its status (500 by default).
Type Parameters
ClassPrototype
ClassPrototype extends Controller
Method
Method
Parameters
r
string
The route, in the syntax of the HTTP adapter (/users/:id); the controller's @Prefix({route}) is prepended to it.
actionOptions
ActionOptions<HTTPContext<{ }>>
The action options: acl runs the access control rules (false by default); name (unique in the HTTP actions, ClassName:method by default), description and groups describe the action; rule is an access rule of the action; middlewares run before the ones @UseMiddlewares adds to the method.
Returns
MethodDecorator<ClassPrototype, Method, ControllerProperty<ClassPrototype>>
The method decorator.
Throws
When the class is declared, if the action options are invalid.
Throws
When the class is declared, if a middleware of the options is neither a function nor a class extending Middleware.
Call Signature
DELETE<
ClassPrototype,Method,DTOConstructor>(r,dtoConstructor,actionOptions):MethodDecorator<ClassPrototype,Method,ControllerProperty<ClassPrototype>>
Expose the controller method as an HTTP DELETE action on a route, its input validated against a DTO, with action options: the shorthand of @HTTPAction(route, 'delete', …). The input is the query string merged with the parsed body, then the route parameters over them (the default of the adapters); the method receives it validated, as a plain object. The value returned is answered as JSON (204 for undefined), an error as {errno, errMsg} with its status (400 for an invalid input, else 500 by default).
Type Parameters
ClassPrototype
ClassPrototype extends Controller
Method
Method
DTOConstructor
DTOConstructor extends typeof DTO = typeof DTO
Parameters
r
string
The route, in the syntax of the HTTP adapter (/users/:id); the controller's @Prefix({route}) is prepended to it.
dtoConstructor
DTOConstructor
The DTO class validating the input; the query values and the route parameters are strings, convert them with .strict(false).
actionOptions
ActionOptions<HTTPContext<{ }>>
The action options: acl runs the access control rules (false by default); name (unique in the HTTP actions, ClassName:method by default), description and groups describe the action; rule is an access rule of the action; middlewares run before the ones @UseMiddlewares adds to the method.
Returns
MethodDecorator<ClassPrototype, Method, ControllerProperty<ClassPrototype>>
The method decorator.
Throws
When the class is declared, if the action options are invalid.
Throws
When the class is declared, if a middleware of the options is neither a function nor a class extending Middleware.