> ## Documentation Index
> Fetch the complete documentation index at: https://docs.riza.io/llms.txt
> Use this file to discover all available pages before exploring further.

# HTTP

> Make outbound HTTP requests

Your script can make outbound HTTP requests using popular HTTP packages for your given language.

## Making outbound HTTP requests

<Note>
  HTTP support is only available in our [JavaScript](/interpreters/javascript) and [Python](/interpreters/python) runtimes.
</Note>

Code you run with the [execute code](/api-reference/command/execute-code)
endpoint can make outbound HTTP requests. By default all HTTP requests are
blocked. Configure allowed hosts and (optionally) associated credentials
with the `http` request parameter.

### Allowed host patterns

Values of the `host` parameter within an allowed HTTP request configuration support two types of pattern matching.

* `*` matches all hosts
* `*.example.com` matches all subdomains of `example.com`, but not `example.com` itself

### Adding authentication credentials

Rather than exposing HTTP authentication credentials to your code, you can pass
credentials to Riza directly and we'll add them to outbound HTTP requests. This
ensures credentials can't be stolen by malicious code.

#### HTTP Basic authentication

```json theme={null}
{
    "http": {
        "allow": [{
            "host": "example.com",
            "auth": {
                "basic": {
                    "user_id": "johny.appleseed",
                    "password": "<password>",
                },
            }
        }]
    }
}
```

#### Bearer token authentication

```json theme={null}
{
    "http": {
        "allow": [{
            "host": "example.com",
            "auth": {
                "bearer": {
                    "token": "<api token>",
                },
            }
        }]
    }
}
```

#### Custom header authentication

```json theme={null}
{
    "http": {
        "allow": [{
            "host": "example.com",
            "auth": {
                "header": {
                    "name": "X-Example-Api-Key",
                    "token": "<api key>",
                },
            }
        }]
    }
}
```

#### Query parameter authentication

```json theme={null}
{
    "http": {
        "allow": [{
            "host": "example.com"
            "auth": {
                "query": {
                    "key": "apikey",
                    "token": "<api key>",
                },
            }
        }]
    }
}
```

<RequestExample>
  ```js Node theme={null}
  import Riza from '@riza-io/api';

  const pythonCode = `
  import requests

  r = requests.get("https://api.ipify.org")
  print(r.text)
  `;

  const riza = new Riza();

  async function main() {
    const resp = await riza.command.exec({
      language: "python",
      code: pythonCode,
      http: {
        allow: [{
          host: "api.ipify.org",
        }]
      }
    });
    console.log(resp);
  }

  main();
  ```

  ```py Python theme={null}
  from rizaio import Riza

  CODE = """
  import requests

  r = requests.get("https://api.ipify.org")
  print(r.text)
  """


  client = Riza()

  resp = client.command.exec(
      language="python",
      code=CODE,
      http={
          "allow": [{
              "host": "api.ipify.org",
          }],
      },
  )

  print(dict(resp))
  ```

  ```go Go theme={null}
  package main

  import (
  	"context"
  	"log"
  	"log/slog"

  	"github.com/riza-io/riza-api-go"
  )

  const pythonCode = `
  import requests

  r = requests.get("https://api.ipify.org")
  print(r.text)
  `

  func main() {
  	client := riza.NewClient()
  	params := riza.CommandExecParams{
  		Language: riza.F(riza.CommandExecParamsLanguagePython),
  		Code:     riza.F(pythonCode),
  		HTTP: riza.F(riza.CommandExecParamsHTTP{
  			Allow: riza.F([]riza.CommandExecParamsHTTPAllow{
  				{
  					Host: riza.F("api.ipify.org"),
  				},
  			}),
  		}),
  	}
  	resp, err := client.Command.Exec(context.Background(), params)
  	if err != nil {
  		log.Fatal(err)
  	}
  	slog.Info(
  		resp.Stdout,
  		"code", resp.ExitCode,
  		"stderr", resp.Stderr,
  	)
  }
  ```
</RequestExample>

<ResponseExample>
  ```json theme={null}
  {
      "exit_code": 0,
      "stdout": "192.108.121.165",
  }
  ```
</ResponseExample>
