Homepage includes a set of built-in proxy handlers that can be used to fetch data from an API. We will go over how to use these proxy handlers and briefly cover how to create your own.
## Available Proxy Handlers
Homepage comes with a few built-in proxy handlers that can be used to fetch data from an API. These handlers are located in the `utils/proxy/handlers` directory.
### `genericProxyHandler`
A proxy handler that makes generally unauthenticated requests to the specified API endpoint.
```js
import genericProxyHandler from "utils/proxy/handlers/generic";
const widgetExample = {
api: "{url}/api/{endpoint}",
proxyHandler: genericProxyHandler,
};
```
You can also pass API keys from the widget configuration to the proxy handler, for authenticated requests.
=== "widget.js"
```js
import genericProxyHandler from "utils/proxy/handlers/generic";
By default the key is passed as an `X-API-Key` header. If you need to pass the key as something else, either add a case to the credentialedProxyHandler or create a new proxy handler.
=== "widget.js"
```js
import credentialedProxyHandler from "utils/proxy/handlers/credentialed";
You can create your own proxy handler to fetch data from an API. A proxy handler is a function that takes a configuration object and returns a function that makes the API request.
The proxy handler function takes three arguments:
-`req`: The request object.
-`res`: The response object.
-`map`: A function that maps the API response to the widget data.
The proxy handler function should return a promise that resolves to the API response.
Here is an example of a simple proxy handler that fetches data from an API and passes it to the widget:
Proxy handlers are a complex topic and require a good understanding of JavaScript and the Homepage codebase. If you are new to Homepage, we recommend using the built-in proxy handlers.