Azure / Azure/azure-functions-nodejs-library
Provide extensibility scenario for `app` namespace
- Dominant language
- TypeScript
- Stars
- 70
- Forks
- 35
- Avg merge
- 4d 18h
- Merged PRs (30d)
- 6
Description
Related to #12. Currently, the `app` object provided from the root of the `@azure/functions` library (in v4), is a namespace:
```TS
import { app } from `@azure/functions`
app.get(/* function*/);
```
This provides limited extensibility when it comes to users/other packages adding their own methods to the root `app` namespace. For example, the Durable SDK had no easy way to add an `app.durableOrchestration()` method to register durable functions, and instead it has to export its own functions under its own namespace.
This issue is to discuss how/if we should provide a way for another package to extend the `app` namespace with their own methods. One such suggestion would be to make `app` an instance of a Class instead of an object, which can then be extended by other packages. Example:
```TS
import { FuncApp } from '@azure/functions'
import * as df from 'durable-functions';
let app = new FuncApp();
app = df.addDurableMagic(app);
app.get(/* HTTP function */); // same methods exist as before
app.durableOrchestration(/* Durable function */); // external package can add its own methods too
```
Instead of using the `new FuncApp()` syntax, which may not be very idiomatic to node, we could also follow Express's model and export a function that does this behind the scenes. Example:
```TS
const func = require('@azure/functions');
const df = require('durable-functions');
let app = func();
app = df.addDurableMagic(app);
// same as before
app.get(/* */);
app.durableOrchestration(/* */);
```
There could be other ways of providing this extensibility too, but this is the easiest one I could think of 🙂
Contributor guide
Assessment
This issue has not been assessed yet.