# Using args

Read a value from the Args of the function instance instead of hardcoding it in the function. Use this pattern when the same code runs on several instances and only a few values change between them, such as an identifier, a feature flag, or a destination hostname.

```js
  async function handleRequest(request, v) {
          return new Response(v, {
              headers: new Headers([
                  ["X-Custom-Header", "something defined on JS"],
              ]),
              status: 200,
          });
      }
      addEventListener("fetch", (event) => {
          event.respondWith(handleRequest(event.request, event.args.value));
      });
```

The Args set on the function instance that runs this code:

```js
{
    "value": "hello_world"
}
```

## How it works

The `fetch` handler reads `event.args.value` and passes it to `handleRequest`, which returns that value in the body of a new `Response`, along with a custom header set through `new Headers([...])` and an explicit `status: 200`. The `value` key comes from the JSON object above, so changing that object changes what the function returns.

Args are not part of the code. You set them on the [function instance](/en/documentation/platform/applications/functions-instances/) that binds the function to an application or a firewall, which is why the same function can behave differently on each instance without being edited or redeployed. [How it works](/en/documentation/platform/functions/how-it-works/) covers the rest of the chain, from the function to the instance to the Rules Engine rule that runs it.

## Related resources

- [JavaScript examples](/en/documentation/platform/functions/javascript-examples.md): Browse the other ready-to-use examples you can copy into a function.
- [Function instances](/en/documentation/platform/applications/functions-instances.md): Create the instance that carries the Args this function reads.
- [FetchEvent](/en/documentation/devtools/runtime/api-reference/fetch-event.md): Reference for the `fetch` event that exposes `event.args`.
- [Functions limits](/en/documentation/platform/functions/limits.md): The ceilings a single invocation of this function runs inside, and the ones that vary by plan.
- [The function fails at instantiation](/en/documentation/platform/functions/troubleshooting.md#the-function-fails-at-instantiation): What an Args object above the ceiling looks like from the outside.
- [Args and environment variables](/en/documentation/platform/functions/best-practices.md#the-split-between-args-and-environment-variables): Why API keys, credentials, and tokens belong in an environment variable rather than in Args.
