Dart - api.route.get()

Register a handler for HTTP GET requests to the route.

import 'package:nitric_sdk/nitric.dart';

final customersRoute = Nitric.api("public").route("/customers");

customersRoute.get((ctx) async {
  // construct response for the GET: /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 GET requests

import 'package:nitric_sdk/nitric.dart';

final customersRoute = Nitric.api("public").route("/customers");

customersRoute.get((ctx) async {
  // construct response for the GET: /customers request...
  final responseBody = {};
  ctx.res.json(responseBody);

  return ctx;
});