# globalSetup() / setup()

## globalSetup(options)

Set any global parameters, headers, etc. that need to be sent with each HTTP request that Frisby sends out.

Most people use this for global headers, authentication, cookies, etc.

### Usage Examples

#### Headers

```javascript
const frisby = require('frisby');

// Do setup first
frisby.globalSetup({
  request: {
    headers: {
      'Authorization': 'Basic ' + Buffer.from("username:password").toString('base64'),
      'Content-Type': 'application/json',
    }
  }
});

// Any global setup is automatically applied to every test
it ('uses globalSetup for every test after it is called', function () {
  return frisby
    .get('http://api.example.com')
    .expect('status', 200);
});
```

## setup(options)

The `setup` method is similar to `globalSetup`, but it only affects a single specific test that it is attached to.

**NOTE: The `setup` call MUST COME BEFORE calls to `get`, `post`, `fetch`, etc.**

### Usage Examples

```javascript
const frisby = require('frisby');

// The 'setup' function only affects a single test
it ('runs setup only for a single test', function () {
  return frisby
    .setup({
      request: {
        headers: {
          'Authorization': 'Basic ' + Buffer.from("username:password").toString('base64')
        }
      }
    })
    .get('http://api.example.com')
    .expect('status', 200);
});
```


---

# 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.frisbyjs.com/api-and-usage/setup.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.
