Comments (3)
Discussed during standup today. We will add a Response
class, but we will not provide res
as a parameter
from azure-functions-nodejs-library.
My feeling is that a res
object is more important in frameworks that rely on callbacks, where you frequently get a bunch of references to objects (err, req, res, etc.) passed as arguments. By contrast, I think a goal of the async/await pattern is to make inputs & outputs more intuitive and IMO res
is clearly an output. We could mix & match qualities of both, but that gets confusing fast. For example, if I modify the body on the res
argument, but return a different object from the promise, which takes priority?
What if we provide a Response
class, but don't pass res
as an argument? Aka your second example code would look like this:
app.get('route', (_, req) => {
const res = new Response({ body: { foo: 'bar' } });
if (req.headers.has('accepts')) {
const accepts = req.headers.get('accepts');
if (accepts.indexOf('application/json')) {
res.headers.add('content-type', 'application/json');
}
}
return res;
});
I've been modeling after undici a lot and they do have both ResponseInit
(a barebones/flexible object) and Response
(a more opinionated/helpful class), so this would be consistent. Of course users would be free to use this new class or just create their own.
from azure-functions-nodejs-library.
As I think about it more, I do think that the "res-as-param" design might be better addressed at a higher-level wrapper over the library, as that's the sort of thing that might be better tied to a framework like Express/Fastify/etc. and not really core to Functions.
Accepting the Response
object as the return value from a Function might be a good idea, as it's clear that this is pretty low level, so using the raw types might be beneficial there. Would also save on having to write type definitions!
from azure-functions-nodejs-library.
Related Issues (20)
- When will Release version 4 of the Node.JS programming model for Azure Functions? HOT 1
- Tutorial HttpTrigger typescript V4 example doesn't register function locally HOT 1
- v4 doesn't detect my functions HOT 2
- v4 programming model - req.json is returning Body is unusable for post with JSON HOT 7
- Ensure v4 model compatibility with Static Web Apps HOT 1
- Add @azure/functions package to js sdk docs
- Add v4 model to trigger reference docs
- How do I reference parameters of output bindings in v4 HOT 3
- Make v4 entry point failures more obvious HOT 6
- Decide how v4 model should handle binding extension breaking changes HOT 6
- Is there any plan for when v4 will become ga HOT 1
- Add SQL trigger support to v4 model
- Queue message value corrupted
- [Azure functions v4.0]: How to get the input from service bus trigger? HOT 2
- Request for: Node.js Version 20 support HOT 1
- Add WebPubSub bindings/trigger type support to v4 model HOT 2
- Phantom functions appear when starting the v4 TypeScript app HOT 2
- Support streams (http) HOT 1
- v4 allow registering separate http methods to the same route HOT 1
- Support streams (azure resources) HOT 10
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 azure-functions-nodejs-library.