functions_framework library

Provides the features needed to define Cloud Functions.

// lib/functions.dart
import 'package:functions_framework/functions_framework.dart';
import 'package:shelf/shelf.dart';

@CloudFunction()
Response function(Request request) => Response.ok('Hello, World!');

Classes

CloudEvent
Represents CloudEvents data.
CloudFunction
Use as an annotation on Functions that will be exposed as endpoints.
RequestContext
Provides access to a RequestLogger, the source Request and response headers for a typed function handler.
RequestLogger
Allows logging at a specified severity.

Typedefs

CloudEventHandler = FutureOr<void> Function(CloudEvent request)
The shape of a handler for CloudEvent types.
CloudEventWithContextHandler = FutureOr<void> Function(CloudEvent request, RequestContext context)
The shape of a handler for CloudEvent types while also providing a RequestContext.
HandlerWithLogger = FutureOr<Response> Function(Request request, RequestLogger logger)
The shape of a basic handler that follows the package:shelf Handler pattern while also providing a RequestLogger.
JsonHandler<RequestType, ResponseType> = FutureOr<ResponseType> Function(RequestType request)
The shape of a handler that supports a custom RequestType and ResponseType.
JsonWithContextHandler<RequestType, ResponseType> = FutureOr<ResponseType> Function(RequestType request, RequestContext context)
The shape of a handler that supports a custom RequestType and ResponseType and while also providing a RequestContext.

Exceptions / Errors

BadRequestException
When thrown in a Handler, configured with badRequestMiddleware or similar, causes a response with statusCode to be returned.