hono icon indicating copy to clipboard operation
hono copied to clipboard

feat: implement azure-functions adapter

Open ytnobody opened this issue 2 years ago • 6 comments

Author should do the followings, if applicable

  • [ ] Add tests
  • [ ] Run tests
  • [ ] yarn denoify to generate files for Deno

usage:

import { Hono } from 'hono'
import { logger } from 'hono/logger'
import { AzureFunction, Context, HttpRequest, handle } from 'hono/adapter/azure-functions'

const app = new Hono()
app.use('*', logger())

app.all('/api/:funcname', async (c) => {
  const message = 'Hello, Azure Functions and Hono!'
  const query = c.req.queries()
  const json_body = c.req.method === "POST" ? await c.req.json() : {};
  const headers = c.req.header()
  return c.json({ message, query, json_body, headers })
})

const httpTrigger: AzureFunction = async function (context: Context, req: HttpRequest): Promise<void> {
  context.log('HTTP trigger function processed a request.')
  context = await handle(app)({ context, req })
}

export default httpTrigger

~requirement~

  • ~@azure/functions ^3.0.0~

ytnobody avatar Dec 09 '23 16:12 ytnobody

I am a developer maintaining an AWS lambda handler

If AzureFunctions user values customizability, this interface looks good.

const httpTrigger: AzureFunction = async function (context: Context, req: HttpRequest): Promise { context.log('HTTP trigger function processed a request.'); context = await handle(app)({ context, req }); };

export default httpTrigger;.

But otherwise, it may be useful to include the async function() part in the handler as well

watany-dev avatar Dec 10 '23 03:12 watany-dev

Hi @ytnobody,

Thank you for the PR. Supporting Azure Functions is a great feature for Hono. We also have issue #1747 .

I will try it out and assess how it feels to use. So, please wait for a moment.

@watany-dev, I might ask you to review this as well.

yusukebe avatar Dec 12 '23 13:12 yusukebe

@ytnobody

I believe the feature in this PR is for 'version 3', but 'version 4' is now available:

https://learn.microsoft.com/en-us/azure/azure-functions/functions-node-upgrade-v4?tabs=v4

Since 'version 3' might no longer be supported, we should update it for 'version 4'.

yusukebe avatar Dec 12 '23 22:12 yusukebe

@yusukebe

I misunderstood about a version that @azure/functions.

This PR will be making changes to support Azure Functions v4.

ytnobody avatar Dec 13 '23 03:12 ytnobody

@ytnobody

Thanks! But, there's no need to hurry!

yusukebe avatar Dec 14 '23 13:12 yusukebe

Hello awesome peeps, any update on this PR? Waiting for this feat for a long time. Would be a lifesaver!

mhsrio avatar Mar 25 '24 04:03 mhsrio

Closing.

You can use https://github.com/Marplex/hono-azurefunc-adapter. Ref: https://github.com/honojs/website/issues/346

yusukebe avatar May 09 '24 05:05 yusukebe