# Runtime Framework

Modern.js BFF supports different runtime frameworks. Currently, Modern.js BFF supports two runtime frameworks: [Express.js](https://expressjs.com/) and [Koa.js](https://koajs.com/).

When using different runtime frameworks, some APIs may differ.

## Accessing Request Context

In BFF functions, you may need to access the request context to handle more logic. Depending on the runtime framework, you need to use different APIs:

import { Tabs, Tab as TabItem } from "@theme";

<Tabs>
  <TabItem value="express" label="Express.js" default>

```ts title="api/lambda/hello.ts"
import { useContext } from '@modern-js/runtime/express'
export const get = async () => {
  const { req } = useContext();
  console.info(`access url: ${req.url}`);
  return 'Hello Modern.js'
};
```

  </TabItem>
  <TabItem value="koa" label="Koa.js">

```ts title="api/lambda/hello.ts"
import { useContext } from '@modern-js/runtime/koa'
export const get = async () => {
  const ctx = useContext();
  console.info(`access url: ${req.url}`);
  return 'Hello Modern.js'
};
```

  </TabItem>
</Tabs>

:::info
For more details, refer to [useContext](/apis/app/runtime/bff/use-context).
:::

## Using Middleware

In BFF functions, you may need to use middleware to handle more logic. Depending on the runtime framework, you need to use different APIs:

<Tabs>
  <TabItem value="express" label="Express.js" default>

```ts title="api/_app.ts"
import { hook } from '@modern-js/runtime/express';

export default hook(({ addMiddleware }) => {
  addMiddleware((req, res, next) => {
    req.query.id = 'koa';
    next();
  });
});
```

  </TabItem>
  <TabItem value="koa" label="Koa.js">

```ts title="api/_app.ts"
import { hook } from '@modern-js/runtime/koa';

export default hook(({ addMiddleware }) => {
  addMiddleware(async (ctx, next) => {
    ctx.req.query.id = 'koa';
    await next();
  });
});
```

  </TabItem>
</Tabs>

:::info
For more details, refer to [hook](/apis/app/runtime/bff/hook).
:::
