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

# api.HTTP

> HTTP запросы без CORS через main процесс Electron

Запросы идут через Node.js в main процессе — никаких CORS ограничений. Можно обращаться к любым внешним API.

## Методы

```js theme={null}
await api.HTTP.get(url, headers?)
await api.HTTP.post(url, body, headers?)
await api.HTTP.put(url, body, headers?)
await api.HTTP.del(url, headers?)
await api.HTTP.request({ url, method, headers, body, timeout })
```

## Ответ

```ts theme={null}
{
  ok:      boolean,  // true если status 200–299
  status:  number,
  headers: object,
  data:    any,      // JSON если парсится, иначе string
}
```

При ошибке сети: `{ ok: false, status: 0, error: string }`

## Параметры request

| Параметр  | По умолчанию | Описание     |
| --------- | ------------ | ------------ |
| `url`     | обязательно  | Полный URL   |
| `method`  | `'GET'`      | HTTP метод   |
| `headers` | `{}`         | Заголовки    |
| `body`    | —            | Тело запроса |
| `timeout` | `15000`      | Таймаут в мс |

## Примеры

<CodeGroup>
  ```js GET theme={null}
  const res = await api.HTTP.get('https://api.example.com/data');
  if (res.ok) api.Logger.log(res.data);
  ```

  ```js POST theme={null}
  const res = await api.HTTP.post(
    'https://api.example.com/track',
    { artist: 'Imagine Dragons', title: 'Bones' }
  );
  ```

  ```js С авторизацией theme={null}
  const res = await api.HTTP.get(
    'https://api.example.com/me',
    { Authorization: 'Bearer ' + api.Storage.get('token') }
  );
  if (!res.ok) api.Logger.warn('Ошибка:', res.status);
  ```
</CodeGroup>
