The Dart SDK is currently in experimental status. If you would like to provide feedback, please reach out to us with your suggestions and comments on our Discord.
Dart - api.delete()
Register an API route and set a specific HTTP DELETE handler on that route.
This method is a convenient short version of api().route().delete()
import 'package:nitric_sdk/nitric.dart';
// Create an API named 'public'
final api = Nitric.api("public");
api.delete("/customers/:customerId", (ctx) async {
// Extract the path parameter
final id = ctx.req.pathParams["customerId"]!;
// Construct response for the DELETE: /customers request...
final responseBody = {};
ctx.res.json(responseBody);
return ctx;
});
Parameters
- Name
match
- Required
- Required
- Type
- String
- Description
The path matcher to use for the route. Matchers accept path parameters in the form of a colon prefixed string. The string provided will be used as that path parameter's name when calling handlers.
- Name
handler
- Required
- Required
- Type
- HttpHandler
- Description
The middleware service to use as the handler for HTTP requests.
- Name
security
- Optional
- Optional
- Type
- List<OidcOptions>
- Description
Security rules to apply with scopes to the entire API.
Examples
Register a handler for DELETE requests
import 'package:nitric_sdk/nitric.dart';
// Create an API named 'public'
final api = Nitric.api("public");
api.delete("/customers/:customerId", (ctx) async {
// Extract the path parameter
final id = ctx.req.pathParams["customerId"]!;
// Construct response for the DELETE: /customers request...
final responseBody = {};
ctx.res.json(responseBody);
return ctx;
});
Access the request body
The DELETE request body is accessible from the ctx.req
object.
import 'package:nitric_sdk/nitric.dart';
// Create an API named 'public'
final api = Nitric.api("public");
api.delete("/customers/:customerId", (ctx) async {
// Extract the path parameter
final id = ctx.req.pathParams["customerId"]!;
// Extract the request body
final body = ctx.req.json();
// Construct response for the DELETE: /customers request...
final responseBody = {};
ctx.res.json(responseBody);
return ctx;
});