# API Connections in Code

## Overview

The rule logic you define will run on your end user's browser. You may want certain network requests in your rule logic to be performed from Feathery's servers instead for security reasons, such as hiding authorization information from the user. To do so, you can leverage `API connectors`, which allow you to run API requests securely from Feathery's servers.

To create a connector, go to `API Connectors` on the `Logic` page and define the API you would like your rule to use. You need to define the method (ex: get, post), and any headers or query parameters you'd like to automatically include for all requests to that endpoint.

Any data you define in the headers or query parameters (such as sensitive API keys) will not be exposed client side to people filling your form.&#x20;

<figure><img src="https://640450274-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHAVngDAEk3s8Bw7P6Ntz%2Fuploads%2FozehSaT7b5YWlbFAgOG2%2Fimage.png?alt=media&#x26;token=257048a4-2cbe-48ac-90f2-40234cadef9d" alt=""><figcaption><p>Defining API Connector</p></figcaption></figure>

After defining the API you want to use, you will be asked to map the response. If you intend to use our Javascript editor to make the API calls, then you can skip this step by pressing the "Skip" button. If you want to use our no-code API connectors feature (which is what this screen below is for), click [here for relevant documentation. ](https://docs.feathery.io/platform/build-forms/advanced-logic/visual-rule-builder/connect-to-api-action)

<figure><img src="https://640450274-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHAVngDAEk3s8Bw7P6Ntz%2Fuploads%2FghokiNiav66ZrN7daHxU%2Fimage.png?alt=media&#x26;token=8b9f2262-f6b4-4b5d-88d6-b95f51c10810" alt=""><figcaption><p>Skip step (unless you want to use no-code API connectors)</p></figcaption></figure>

Then, go to your rule code and make a network request to the API connector via the `feathery.http` interface. By defining the API connector, it will automatically pass in the relevant connector parameters (headers, body, parameters, etc.) on the server side in a secure manner.

<figure><img src="https://640450274-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHAVngDAEk3s8Bw7P6Ntz%2Fuploads%2F5JNXvxgEyuJAPIoPttsO%2Fimage.png?alt=media&#x26;token=66bc274a-b83a-4e04-8842-c59b48ba8fd3" alt=""><figcaption><p>API connector request example via Javascript code</p></figcaption></figure>

## Usage

You can use the `feathery.http` interface in one of two ways - a simple connector name-based approach and a more advanced, customizable approach.

### Simple

The simplest way to call the API connector is to run `feathery.http.connect(<connector name>)`where the name of the connector is what you specified when creating it. This allows for no additional customization of data on top of the connector.

### Customizable

In this approach, you call the connector via `feathery.http.<method>(<url>, <data>, <headers>)` . The right connector to use will be inferred based on matching the method and URL passed in to the method and URL defined on API connectors themselves. The URL passed into this request must contain the defined URL of the relevant API connector as a substring.

* `method` is a standard REST method: `get`, `post`, `put`, `patch`, `delete`
* `url`is an endpoint you're requesting that contains a defined API connector URL as a substring.
* `data` is the request body, which you should pass in an `Object` or `Array` format. This is merged with the request body defined on the connector config itself, if specified.
  * For example, `{email: <email>, name: <name>}`
* `headers` are additional headers you'd like to pass in an `Object` format. These are also merged with headers defined on the connector config itself.
  * For example, `{Authorization: 'Bearer <token>', 'Accept-Encoding': 'gzip'}`

For `get` requests, make sure to append query and URL parameters directly to the URL rather than attempting to set it via `data`, which is only used for the request body.

## IP Address Whitelist

All API connector requests originate from the static IP address `54.177.134.134`. You may whitelist this IP address to improve the security of your endpoint that's receiving Feathery API connector requests.

## Variables

When defining and using your connectors, you will also have access to [backend variables](https://docs.feathery.io/platform/build-forms/visual-rule-builder/connect-to-api-action#variables) that can be included via double curly braces.

## Example

You're looking to fetch a list of dog breeds via `https://dog.ceo/api/breeds/list/all` from Feathery's servers. First, create the API connector.

<figure><img src="https://640450274-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHAVngDAEk3s8Bw7P6Ntz%2Fuploads%2FFclDoxOMdxJjtebSXVx0%2Fimage.png?alt=media&#x26;token=5ffe44ca-0ddc-4eb9-bdcd-087161b03ac2" alt=""><figcaption></figcaption></figure>

Then, use the `feathery.http` interface to access the API connector from your logic rule.

<figure><img src="https://640450274-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHAVngDAEk3s8Bw7P6Ntz%2Fuploads%2F9sSnWPFHffdwcffokxyo%2FScreenshot%202024-10-08%20at%2012.54.58%E2%80%AFAM.png?alt=media&#x26;token=fbdabb3c-749e-4075-9f62-d24f5926c2d7" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.feathery.io/platform/build-forms/advanced-logic/javascript-rule-builder/api-connections-in-code.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
