Hacker News new | ask | show | jobs
by runarberg 971 days ago
The fetch API is implemented in node and is provided as globals since node 18. So node-fetch is effectivly obsolete at this point.

What I’m looking for is a server framework (like express.js) which uses these standards instead of their home made APIs. So instead of:

    app.use(json());
    app.get("/echo", (req, res) {
      const { message } = req.body;

      res.append("Content-Type", "application/json");
      res.send(JSON.stringify({ message }));
    });
I could write something like:

    app.get("/echo", async (request) => {
      const { message } = await request.json();
      const headers = new Headers([[ "Content-Type", "application/json" ]]);

      return new Response(
        JSON.stringify({ message }),
        { headers },
      );
    });