@@ -619,8 +619,17 @@ func validate(ctx *handler.HttpContext, next handler.HttpHandler) (*handler.Http
619619}
620620```
621621
622- ``` txt {{ language: 'dart' }}
623- Middleware currently not supported in dart
622+ ``` dart
623+ Future<HttpContext> validate(HttpContext ctx) async {
624+ if (ctx.req.headers.containsKey("content-type")) {
625+ ctx.res.status = 400;
626+ ctx.res.body = "header Content-Type is required";
627+
628+ return ctx;
629+ }
630+
631+ return ctx.next();
632+ }
624633```
625634
626635</CodeGroup >
@@ -684,8 +693,16 @@ func main() {
684693}
685694```
686695
687- ``` txt {{ language: 'dart' }}
688- API level middleware currently not supported in dart
696+ ``` dart
697+ import 'package:nitric_sdk/nitric.dart';
698+ import '../middlewares';
699+
700+ final customersApi = Nitric.api(
701+ "customers",
702+ opts: ApiOptions(
703+ middlewares: [logRequest, validate],
704+ )
705+ );
689706```
690707
691708</CodeGroup >
@@ -735,8 +752,7 @@ func validate(ctx *handler.HttpContext, next handler.HttpHandler) (*handler.Http
735752}
736753
737754func main () {
738- customersApi , err := nitric.NewApi (
739- " customers" )
755+ customersApi , err := nitric.NewApi (" customers" )
740756
741757 if err != nil {
742758 return
@@ -752,8 +768,22 @@ func main() {
752768}
753769```
754770
755- ``` txt {{ language: 'dart' }}
756- Route level middleware currently not supported in dart
771+ ``` dart
772+ import 'package:nitric_sdk/nitric.dart';
773+ import '../middlewares';
774+
775+ Future<HttpContext> getAllCustomers(HttpContext ctx) async {
776+ // gets the customers
777+ return ctx.next();
778+ }
779+
780+ final customersApi = Nitric.api("customers");
781+
782+ // Inline using .get()
783+ customersApi.get("/customers", getAllCustomers, middlewares: [logRequest, validate]);
784+
785+ // Inline using .route()
786+ customersApi.route("/customers").get(getAllCustomers, middlewares: [logRequest, validate]);
757787```
758788
759789</CodeGroup >
0 commit comments