@helperdiscord/centra
A cool library to use for rest requests in nodejs :) docs
Examples
Basic GET Request
const req = require('@helperdiscord/centra');
const res = await req('https://discord.com/api/gateway').json()
console.log(res);
// { url: 'wss://gateway.discord.gg' }
Simple POST Request with payload
const req = require('@helperdiscord/centra');
const res = await req('https://discord.com/api/channels/418933739540840451/messages', 'POST').body({ content: 'hi' }).header({ 'Authorization': 'Bot youryoken' }).json()
console.log(res);
/* {
id: '805925621561163806',
type: 0,
content: 'hi',
channel_id: '418933739540840451',
author: [Object],
attachments: [],
embeds: [],
mentions: [],
mention_roles: [],
pinned: false,
mention_everyone: false,
tts: false,
timestamp: '2021-02-01T22:20:41.554000+00:00',
edited_timestamp: null,
flags: 0,
referenced_message: null
} */
Type casting json responses
import req from '@helperdiscord/centra';
type Gateway {
url: string
}
const res = await req('https://discord.com/api/gateway').json<Gateway>();
@helperdiscord/centra vs other http libraries
Here's a size comparison table:
Here you can see how efficient @helperdiscord/centra is compared in bundle size to other libraries
Package | Size |
---|---|
request | |
superagent | |
got | |
axios | |
isomorphic-fetch | |
r2 | |
node-fetch | |
phin | |
@helperdiscord/centra |
Here's a performance comparison of @helperdiscord/centra vs other http libraries
These results were procured using this
Results (i7-7700k, CPU governor: performance):
got - promise x 2,770 ops/sec ±6.67% (71 runs sampled)
request - callback x 4,888 ops/sec ±7.46% (74 runs sampled)
node-fetch - promise x 5,457 ops/sec ±3.33% (74 runs sampled)
centra - promise x 8,263 ops/sec ±2.10% (84 runs sampled)
https - stream x 7,453 ops/sec ±3.19% (78 runs sampled)
@helperdiscord/centra - promise x 8,202 ops/sec ±1.30% (82 runs sampled)
Fastest is @helperdiscord/centra - promise