Boss Machine - Solved the project but don't understand why res.send makes the difference?

Hey all!

So I’m currently working on Boss Machine: [https://www.codecademy.com/paths/web-development/tracks/javascript-back-end-development/modules/express-cumulative-project/informationals/bapi-p4-boss-machine]

For the Post-request for minions (creating a new minion) I had this code in Express earlier:

// Create A New Minion
minionsRouter.post('/', (req, res) => {
    const name = req.body.name;
    const title = req.body.title;
    const salary = req.body.salary;
    const weaknesses = req.body.weaknesses;
    
    if (name === "" || title === "" || salary === "" || weaknesses === "") {
        res.status(400).send();
    }
    else {
        req.body.salary = Number(salary);
        db.addToDatabase('minions', req.body);
    }
});

It created a new minion successfully.
However, when I went back to the /minions - route (to see the listing of all minions) I had to refresh my browser to see the new updated listing including the new minion = It wasn’t there initially without refresh.

However, when I added res.send to the code in the bottom, I didn’t have to refresh my browser to see the new minion. The code that works without refresh looks like this:

// Create A New Minion
minionsRouter.post('/', (req, res) => {
    const name = req.body.name;
    const title = req.body.title;
    const salary = req.body.salary;
    const weaknesses = req.body.weaknesses;
    
    if (name === "" || title === "" || salary === "" || weaknesses === "") {
        res.status(400).send();
    }
    else {
        req.body.salary = Number(salary);
        const newMinion = db.addToDatabase('minions', req.body);
        res.status(201).send(newMinion);
    }
});

I’m curious to know why this is the case. Why does adding the res.send in the bottom eliminate the need for refreshing the browser to see the new minion in the list?

The same was the case for the .delete. Adding a res.send there eliminated the need for refreshing the browser. However, the put statement worked right out of the box without having to use res.send. That’s what kind of is making me confused… I don’t understand why res.send works like this for post and delete.

I love this forum btw, thanks for being a part for this and thanks to all of you awesome programmers out there :slight_smile: