## Documentation index

This index lists every available documentation page and its Markdown source.

- [Documentation](https://veta.varavel.com/docs/index.md)
  - [Getting Started](https://veta.varavel.com/docs/getting-started/index.md)
  - [Installation](https://veta.varavel.com/docs/installation/index.md)
  - [Guides](https://veta.varavel.com/docs/guides/index.md)
    - [Project Structure](https://veta.varavel.com/docs/guides/project-structure/index.md)
    - [Configuration](https://veta.varavel.com/docs/guides/configuration/index.md)
    - [Pages](https://veta.varavel.com/docs/guides/pages/index.md)
    - [Data](https://veta.varavel.com/docs/guides/data/index.md)
    - [Markdown](https://veta.varavel.com/docs/guides/markdown/index.md)
    - [Templates](https://veta.varavel.com/docs/guides/templates/index.md)
    - [Components](https://veta.varavel.com/docs/guides/components/index.md)
    - [Filters](https://veta.varavel.com/docs/guides/filters/index.md)
    - [Assets And Tailwind CSS](https://veta.varavel.com/docs/guides/assets-and-tailwind/index.md)
    - [Themes](https://veta.varavel.com/docs/guides/themes/index.md)
    - [Development Server](https://veta.varavel.com/docs/guides/development-server/index.md)
    - [Build And Output](https://veta.varavel.com/docs/guides/build-and-output/index.md)
    - [Deployment](https://veta.varavel.com/docs/guides/deployment/index.md)
  - [Reference](https://veta.varavel.com/docs/reference/index.md)
    - [CLI Reference](https://veta.varavel.com/docs/reference/cli/index.md)
    - [Config Reference](https://veta.varavel.com/docs/reference/config/index.md)
    - [Page Generators Reference](https://veta.varavel.com/docs/reference/page-generators/index.md)
    - [Template Context Reference](https://veta.varavel.com/docs/reference/template-context/index.md)
    - [Troubleshooting](https://veta.varavel.com/docs/reference/troubleshooting/index.md)
  - [API](https://veta.varavel.com/docs/api/index.md)
    - [JavaScript API](https://veta.varavel.com/docs/api/javascript/index.md)
    - [File API](https://veta.varavel.com/docs/api/files/index.md)
    - [HTTP Client](https://veta.varavel.com/docs/api/http-client/index.md)
    - [Parse API](https://veta.varavel.com/docs/api/parse/index.md)
    - [Template Functions](https://veta.varavel.com/docs/api/template-functions/index.md)
    - [Environment And Console](https://veta.varavel.com/docs/api/environment-and-console/index.md)
    - [Markdown Frontmatter](https://veta.varavel.com/docs/api/frontmatter/index.md)


## Documentation content

The documentation for the current page follows, reproduced verbatim.


# HTTP Client

The HTTP client is available as `httpClient` in JavaScript context objects.

It is synchronous and supports HTTP and HTTPS URLs only.

## Shortcut Methods

```js
httpClient.get(url, options);
httpClient.post(url, options);
httpClient.put(url, options);
httpClient.patch(url, options);
httpClient.delete(url, options);
httpClient.head(url, options);
```

Example:

```js
export default function({ httpClient, parse }) {
  const response = httpClient.get(
    "https://api.github.com/repos/varavelio/veta",
    {
      headers: {
        Accept: "application/vnd.github+json",
      },
    },
  );

  if (!response.ok) {
    throw new Error(`GitHub returned ${response.status}`);
  }

  return parse.json(response.body);
}
```

## Explicit Request Method

```js
httpClient.request("GET", "https://example.com/data.json");
```

The method is trimmed and uppercased. Empty methods or methods containing whitespace are rejected.

## Options

```js
{
  headers: {
    "Accept": "application/json",
    "X-Trace": ["one", "two"]
  },
  body: "raw body",
  timeoutMs: 5000
}
```

`body` must be a string.

For JSON request bodies, use `JSON.stringify` and set the content type yourself:

```js
httpClient.post("https://example.com/api", {
  body: JSON.stringify({ message: "hello" }),
  headers: { "Content-Type": "application/json" },
});
```

`timeoutMs` must be a positive number. The default timeout is 30 seconds.

## Response Shape

```js
{
  body: "...",
  headers: {
    "Content-Type": ["application/json"]
  },
  ok: true,
  status: 200,
  statusText: "OK",
  url: "https://example.com/data.json"
}
```

`ok` is `true` for status codes from 200 through 299.

`body` is always a string. Use `parse.json`, `parse.yaml`, or another parser when you need structured data.

## Development Advice

`veta dev` performs a full rebuild on file changes. If a data script fetches slow remote APIs, it will fetch them again on rebuild. For development, consider using `env` to return local mock data.
