Comments (2)
Not a bug, will close this issue and reopen another as a feature enhancement to be able to parameterize @cloudfunction for different HTTP verbs or alternatively to recognize a specific function naming convention (handlePost
, etc.)
from functions-framework-dart.
Scratch that, reopening because this does appear in fact to be problematic.
Overview
In the current implementation the @cloudfunction() annotation maps an external target name to an internal function.
Using the @cloudfunction() annotation without an argument maps function
as the default external target name to an internal function.
When providing a name as an argument to @cloudfunction() to override the default name function
, then this name must also be set corresponding FUNCTION_TARGET
environment variable or --target
command line option, as shown below.
Default function
In the following example, the @cloudfunction external target default name is function
, which will be mapped to the internal handleGet
function. Since function
is the default external target name, it isn't necessary to set the FUNCTION_TARGET
environment variable or --target
command line option.
// default `function` is mapped to `handleGet`
@CloudFunction()
Response handleGet(Request request) => Response.ok('Hello, World!');
Overridding the default
In the next example, the @cloudfunction external target name is explicitly set to foo
, which will be mapped to the internal bar
function. Since foo
overrides the default external target name function
, either the FUNCTION_TARGET
environment variable or --target
command line option must be set to foo
.
@CloudFunction('foo')
Response bar(Request request) => Response.ok('Hello, World!');
To invoke foo
, either of the following would work:
FUNCTION_TARGET=foo dart run bin/main.dart
or
dart run bin/main.dart --target=foo
The problem
The problem with the current implementation is twofold:
- The need for target mapping is not obvious and somewhat confusing.
- There can only be one function annotated with @cloudfunction. The expectation would be that there could be several declarations.
Consider the following:
// handle HTTP GET requests by convention
@CloudFunction()
Response handleGet(Request request) { ... }
// handle HTTP POST requests by convention
@CloudFunction()
Response handlePost(Request request) { ... }
// handle request for conformance testing
@CloudFunction()
Response writeHttp(Request request) { /* write `request.body` contents to file: `function_output.json` */ }
To invoke writeHttp
for conformance testing, either of the following should work:
FUNCTION_TARGET=writeHttp dart run bin/main.dart
or
dart run bin/main.dart --target=writeHttp
Resolution
Resolving this requires a bit more thought around the desired developer experience. The current implementation works as originally designed, so I'm closing this issue (again) and will open another issue with a proposal for an updated approach to better match expectations.
from functions-framework-dart.
Related Issues (20)
- sample project created via dartfn should use official docker images HOT 3
- Docker files created by dartfn doesn't copy runtime files, causing launch to fail HOT 3
- dartfn-generated project fails tests locally HOT 9
- dartfn: need to have a dependency to pkg:lints!
- dartfn: gitignore files should link to https://dart.dev/guides/libraries/private-files
- Cloud Run + Cloud SQL hanging issue HOT 25
- Pricing and/or other considerations regarding using Cloud Run for simulating Cloud Functions?
- Multiple functions in the same package HOT 3
- Docker images failing when deployed to cloud run when using apple silicon HOT 1
- Private SSH packages HOT 1
- Generated project (from dartfn) logs CloudEvent awkwardly HOT 3
- Allow Configuring "X-Powered-By" of underlying shelf server HOT 1
- Support for Protobufs in CloudEvents HOT 6
- Provide access to an instance's region from metadata HOT 1
- gcp: logging does not support jsonPayload HOT 1
- DRY up finishServerTest code and similar HOT 2
- Multiple funcitons in one project HOT 3
- BuildRunner seems to break the code HOT 7
- "Not compatible with a supported function shape" when using RequestContext parameter HOT 12
- Question about logging HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from functions-framework-dart.