# @skyra/http-framework

> The framework for ArchId Network's HTTP-only bots

Latest version **2.2.1** (published 2025-05-22) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @skyra/http-framework
pnpm add @skyra/http-framework
yarn add @skyra/http-framework
bun add @skyra/http-framework
```

## Health

**Score 60/100 (C)** — status: stable.

Positive: has types; esm support; no vulnerabilities; has provenance; high maintenance score; high quality score.

Warnings: low downloads.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 2.2.1 |
| Published | 2025-05-22 |
| First published | 2022-03-13 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=18 |
| Dependencies | 9 |
| Unpacked size | 512.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 20 |
| Author | @skyra |
| Maintainers | favna, kyranet |
| Keywords | discord, api, http, skyra, typescript, ts, yarn |

## Links

- npm: https://www.npmjs.com/package/@skyra/http-framework
- Repository: https://github.com/skyra-project/archid-components
- Issues: https://github.com/skyra-project/archid-components/issues
- npm.io page: https://npm.io/package/@skyra/http-framework

## Dependencies (9)

- [@discordjs/rest](https://npm.io/package/@discordjs/rest.md) ^2.5.0
- [@discordjs/util](https://npm.io/package/@discordjs/util.md) ^1.1.1
- [@sapphire/pieces](https://npm.io/package/@sapphire/pieces.md) ^4.4.0
- [@sapphire/result](https://npm.io/package/@sapphire/result.md) ^2.7.2
- [discord-api-types](https://npm.io/package/discord-api-types.md) ^0.38.8
- [@discordjs/builders](https://npm.io/package/@discordjs/builders.md) ^1.11.2
- [@sapphire/utilities](https://npm.io/package/@sapphire/utilities.md) ^3.18.2
- [@discordjs/collection](https://npm.io/package/@discordjs/collection.md) ^2.1.1
- [@vladfrangu/async_event_emitter](https://npm.io/package/@vladfrangu/async_event_emitter.md) ^2.4.6

## Alternatives

- [launchdarkly-js-client-sdk](https://npm.io/package/launchdarkly-js-client-sdk.md) — 2.5M weekly downloads
- [@elastic/elasticsearch](https://npm.io/package/@elastic/elasticsearch.md) — 2.1M weekly downloads
- [@c8y/client](https://npm.io/package/@c8y/client.md) — 15.3K weekly downloads
- [@signaldb/maverickjs](https://npm.io/package/@signaldb/maverickjs.md) — 1.7K weekly downloads
- [@bbc/http-transport-cache](https://npm.io/package/@bbc/http-transport-cache.md) — 1.2K weekly downloads

## Recent versions

- 2.2.1 (latest) — 2025-05-22
- 2.2.2-next.03b76f1 (next) — 2025-11-28
- 2.2.2-next.3d1dd78 — 2025-11-09
- 2.2.2-next.a6dc396 — 2025-11-08
- 2.2.2-next.5127658 — 2025-11-02
- 2.2.2-next.b697e9a — 2025-10-31
- 2.2.2-next.2342e6a — 2025-10-31
- 2.2.2-next.bc3bef6 — 2025-10-26
- 2.2.2-next.c30e173 — 2025-10-19
- 2.2.2-next.1f3bf30 — 2025-10-19
- 2.2.2-next.58c9939 — 2025-10-12
- 2.2.2-next.437382b — 2025-10-05
- 2.2.2-next.d629d70 — 2025-09-28
- 2.2.2-next.c85ed25 — 2025-09-28
- 2.2.2-next.0031e55 — 2025-09-07
- … 156 more at https://npm.io/package/@skyra/http-framework/versions

## README

# `@skyra/http-framework`

A powerful HTTP framework for building your Discord bots, powered by [`node:http`], [`@discordjs/rest`], and [`@sapphire/pieces`].

## Features

-   Support for reloading and unloading commands
-   Support for attachment responses
-   Seamless integration with low-level libraries
-   Thin wrapper on top of raw data for maximum performance

## Usage

This library can handle both HTTP interactions and registering commands both globally and per guild using an integrated design powered by decorators.

### Command

The Command is a piece that runs for all chat input and context menu interactions, including auto-complete (since this one is sort of part of the former). Registering the commands happens with decorators:

```typescript
import { Command, RegisterCommand } from '@skyra/http-framework';

@RegisterCommand((builder) =>
	builder //
		.setName('ping')
		.setDescription('Runs a network connection test with me')
)
export class UserCommand extends Command {
	public override chatInputRun(interaction: Command.ChatInputInteraction) {
		return interaction.sendMessage({ content: 'Pong!' });
	}
}
```

You can also register subcommands via decorators:

```typescript
import { Command, RegisterCommand, RegisterSubcommand } from '@skyra/http-framework';

@RegisterCommand((builder) =>
	builder //
		.setName('math')
		.setDescription('Does some maths.')
)
export class UserCommand extends Command {
	@RegisterSubcommand(buildSubcommandBuilders('add', 'Adds the first number to the second number'))
	public add(interaction: Command.ChatInputInteraction, { first, second }: Args) {
		return interaction.sendMessage({
			content: `The result is: ${first + second}`
		});
	}

	@RegisterSubcommand(buildSubcommandBuilders('subtract', 'Subtracts the second number from the first number'))
	public subtract(interaction: Command.ChatInputInteraction, { first, second }: Args) {
		return interaction.sendMessage({
			content: `The result is: ${first - second}`
		});
	}
}

function buildSubcommandBuilders(name: string, description: string) {
	return new SlashCommandSubcommandBuilder() //
		.setName(name)
		.setDescription(description)
		.addNumberOption((builder) =>
			builder //
				.setName('first')
				.setDescription('The first number.')
				.setRequired(true)
		)
		.addNumberOption((builder) =>
			builder //
				.setName('second')
				.setDescription('The second number.')
				.setRequired(true)
		);
}

interface Args {
	first: number;
	second: number;
}
```

### Client

The `Client` class contains the HTTP server, powered by [`node:http`], it also registers a handler that processes whether or not the HTTP request comes from Discord and processes the information accordingly, handling the heavyweight in the background.

```typescript
import { Client } from '@skyra/http-framework';

const client = new Client({
	discordToken: process.env.DISCORD_TOKEN,
	discordPublicKey: process.env.DISCORD_PUBLIC_KEY
});

// Load all the commands and message component handlers:
await client.load();

// Start up the HTTP server;
await client.listen({ port: 3000 });
```

### ApplicationCommandRegistry

The `ApplicationCommandRegistry` is `@skyra/http-framework`'s centralized registry and uses [`@discordjs/rest`] to register them in Discord.

```typescript
// Assuming you have the code above, and that you called `client.load()`:

// Register all global commands:
await client.registry.pushGlobalCommands();

// Register all the guild-restricted commands:
await client.registry.pushGuildRestrictedCommands();
```

However, if you want to use the registry without the client, you can do so:

```typescript
import { applicationCommandRegistry } from '@skyra/http-framework';
import { REST } from '@discordjs/rest';

applicationCommandRegistry.setup({
	rest: new REST({ version: '10' }).setToken(process.env.DISCORD_TOKEN),
	clientId: process.env.DISCORD_CLIENT_ID
});

// Load all the commands:
await applicationCommandRegistry.loadCommands();

// Register all global commands:
await applicationCommandRegistry.pushGlobalCommands();

// Register all the guild-restricted commands:
await applicationCommandRegistry.pushGuildRestrictedCommands();
```

> **Note**: calling `applicationCommandRegistry.setup()` is not needed if you are using the `Client` class because it is
> already called automatically for you.

[`node:http`]: https://nodejs.org/api/http.html
[`@discordjs/rest`]: https://www.npmjs.com/package/@discordjs/rest
[`@sapphire/pieces`]: https://www.npmjs.com/package/@sapphire/pieces

---
_Source: https://npm.io/package/@skyra/http-framework · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
