# Handlers

import Code from '~/components/Code/Code.astro'
import Tabs from '~/components/tabs/Tabs'

**Azion Functions** supports JavaScript handlers. Handler functions let you control how your edge logic manages incoming requests, applies security rules, and interacts with the runtime environment. You can define handler functions by using either the ES Modules pattern or the Service Worker syntax.
With Javascript Handlers you can:

- Respond to fetch (HTTP request) events.
- Apply firewall and access control logic.
- Perform asynchronous operations during request processing.


<Tabs client:visible>
    <Fragment slot="tab.fetch">Fetch</Fragment>
    <Fragment slot="tab.firewall">Firewall</Fragment>

<Fragment slot="panel.fetch">

<Code lang="javascript" code={`
export default {
  async fetch(request, env, ctx) {
    return new Response('Hello World!');
  },
};
`} />

### Parameters:

| Parameter | Type | Description |
|-----------|------|-------------|
| `request` | Request | HTTP request object |
| `env` | Object | Environment variables and bindings |
| `ctx` | Object | Execution context |
| `ctx.waitUntil(promise)` | Function | Extends the worker's lifetime |

</Fragment>

<Fragment slot="panel.firewall">

<Code lang="javascript" code={`
export default {
  async firewall(request, env, ctx) {
    return new Response('Hello World!');
  },
};
`} />

### Parameters:

| Parameter | Type | Description |
|-----------|------|-------------|
| `request` | Request | HTTP request object |
| `env` | Object | Environment variables and bindings |
| `ctx` | Object | Execution context |
| `ctx.deny()` | Function | Blocks the request immediately (ES Modules pattern only). If not called, the request continues to the fetch handler |


</Fragment>

</Tabs>