#What's the best package for service-to-service calls..

27 messages · Page 1 of 1 (latest)

rough rampart

I'm working on a project which includes vite, express and discord.js. I'm not using express along with discord.js. So from express, I need to make a request to discord.js to do some process and i should get it's progress log (manual, put a code where you need the log). I researched but still confused..

steady elmBOT
  • Consider reading #how-to-get-help to improve your question!
  • Explain what exactly your issue is.
  • Post the full error stack trace, not just the top part!
  • Show your code!
  • Issue solved? Press the button!
  • Marked as resolved by OP
chilly gyro

I‘m just as confused by your question. You don’t use express along with express? What kind of request do you want to do to discord.js (assuming you just mean a REST request to discord API you should use @discordjs/rest or /core instead of full discord.js)

fading thicket
rough rampart
router.post('/events', async (req, res, next) => {
    res.setHeader('Content-Type', "text/event-stream");
    res.setHeader('Cache-Control', 'no-cache');
    res.setHeader('Connection', 'keep-alive');

    res.write(`data: ${JSON.stringify({ message: "Saving Data", progress: 25 })}`);

    setTimeout(() => {
        res.write(`\ndata: ${JSON.stringify({ message: "Creating Role", progress: 50 })}`);
    }, 3000);

    setTimeout(() => {
        res.write(`\ndata: ${JSON.stringify({ message: "Assigning Role", progress: 75 })}`);
    }, 6000);
    
    setTimeout(() => {
        res.write(`\ndata: ${JSON.stringify({ message: "Completed..", progress: 100 })}`);
    }, 9000);
    setTimeout(() => {
        res.end();
    }, 12000);
    
    res.on('close', () => {
        res.end();
    })
})

This is a sample code which returns some stream data using express.. On each, I need to make a request to bot side and i should get a response also... I implemented it using socket io but IT'S A LOT OF EVENTS

chilly gyro

what kind of request and what is "bot side" here? another node process running your bot with djs? djs running in the same process? or direct requests to discord without having a logged in djs bot with gateway connection?

rough rampart
chilly gyro

what kind of request?
and what do you mean by "with api"?

rough rampart

but you know, dealing discord api with discord.js is kinda ezzz

rough rampart
chilly gyro

then use either @discordjs/rest to send the raw requests or @discordjs/core to have typed functions for the request routes

lime shadowBOT
rough rampart
rough rampart

oke, this package helps me a lot.. but i think i should connect with discord.js application to handle them properly.. so is there any packages which i can use for service-to-service calls? like I need to request (a process to create) and i should get a responce from the djs node process

chilly gyro

make an API server with express

rough rampart
chilly gyro

So you want to do it. While not doing it… what exactly is it you want?

rough rampart

I just need to request a process from the express application to djs node process (both are different applications)..

so for that, what's the best package for service-to-service calls ( i should get a responce too)

chilly gyro

„Request a process“? Wdym by that?

rough rampart
chilly gyro

And why are you

  • not doing the API request to discord that does that from the express app or
  • run the express endpoint from the djs app?

Because what you call service-to-service calls is nothing else but an API

rough rampart
rough rampart
chilly gyro

I‘m sorry but it‘s hard to follow what you mean… yeah