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.route.put()
Register a handler for HTTP PUT requests to the route.
import 'package:nitric_sdk/nitric.dart';
final customersRoute = Nitric.api("public").route("/customers");
customersRoute.put((ctx) async {
// construct response for the PUT: /customers request...
final responseBody = {};
ctx.res.json(responseBody);
return ctx;
});
Parameters
- 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 PUT requests
import 'package:nitric_sdk/nitric.dart';
final customersRoute = Nitric.api("public").route("/customers");
customersRoute.put((ctx) async {
// construct response for the PUT: /customers request...
final responseBody = {};
ctx.res.json(responseBody);
return ctx;
});
Access the request body
The PUT request body is accessible from the ctx.req
object.
import 'package:nitric_sdk/nitric.dart';
final customersRoute = Nitric.api("public").route("/customers");
customersRoute.put((ctx) async {
final customerData = ctx.req.json();
// parase, validate and store the request payload if it's available
return ctx;
});