You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In previous versions, creating Azure Functions with Hono required repetitive and verbose setups. For instance, setting up a simple HTTP trigger looked like this:
import{Hono}from'hono';import{HonoAzureMiddleware,register}from'nammatham';// DO NOT SET `basePath` for Hono App, Azure Functions will handle itconstapp=newHono();constfunc=newHonoAzureMiddleware();app.all(...func.get('/SimpleHttpTrigger'),c=>{// Getting the function contextconstcontext=c.var.context;context.log(`invocationid is: ${context.invocationId}`);returncontext.json({hello: 'world',});});exportdefaultregister({fetch: app.fetch,
func,});
This approach generated separate function.json files for each endpoint, such as SimpleHttpTrigger/function.json, creating redundant configuration and coupling Azure Functions routing with Hono routing.
Using a single function.json for multiple endpoints.
Delegating routing to Hono instead of Azure Functions.
This approach is cleaner and reduces overhead by leveraging Hono for routing while using Azure Functions primarily as a handler.
Proposal
To align with best practices and streamline API usage, the new version (v3) should:
1. Use HonoAzureMiddleware as a Global Middleware
By introducing HonoAzureMiddleware globally, we can intercept and format all requests/responses to conform with Azure Functions conventions. This results in a simpler API and better scalability:
import{Hono}from'hono';import{HonoAzureMiddleware,register}from'nammatham';constfunc=newHonoAzureMiddleware();constapp=newHono().use(func.middleware);app.get('/aaa',(c)=>{constcontext=c.var.context;context.log(`invocationid is: ${context.invocationId}`);returncontext.json({hello: 'world',});});exportdefaultregister({fetch: app.fetch,
func,});
2. Support Native Azure Functions Triggers
To ensure flexibility, HonoAzureMiddleware should natively support Azure Functions triggers (e.g., TimerTrigger). For example:
func.timer('myTimer','*/5 * * * * *',async(c)=>{constcontext=c.var.context;context.log(`invocationid is: ${context.invocationId}`);});
The framework should handle trigger registration and automatically generate the corresponding function.json file (e.g., myTimer/function.json).
Benefits
Cleaner API: Reduces boilerplate by centralizing middleware and routing logic.
Unified Routing: Keeps routing logic within Hono while simplifying Azure Functions configuration.
Extended Functionality: Supports various Azure Functions triggers natively.
Improved Maintainability: Minimizes redundancy in function.json generation.
The text was updated successfully, but these errors were encountered:
Background
In previous versions, creating Azure Functions with Hono required repetitive and verbose setups. For instance, setting up a simple HTTP trigger looked like this:
This approach generated separate
function.json
files for each endpoint, such asSimpleHttpTrigger/function.json
, creating redundant configuration and coupling Azure Functions routing with Hono routing.Observations from Existing Solutions
The Marplex/hono-azurefunc-adapter, as referenced in the official Hono documentation, simplifies this process by:
function.json
for multiple endpoints.This approach is cleaner and reduces overhead by leveraging Hono for routing while using Azure Functions primarily as a handler.
Proposal
To align with best practices and streamline API usage, the new version (
v3
) should:1. Use
HonoAzureMiddleware
as a Global MiddlewareBy introducing
HonoAzureMiddleware
globally, we can intercept and format all requests/responses to conform with Azure Functions conventions. This results in a simpler API and better scalability:2. Support Native Azure Functions Triggers
To ensure flexibility,
HonoAzureMiddleware
should natively support Azure Functions triggers (e.g.,TimerTrigger
). For example:The framework should handle trigger registration and automatically generate the corresponding
function.json
file (e.g.,myTimer/function.json
).Benefits
function.json
generation.The text was updated successfully, but these errors were encountered: