3 ms·
Follow-up question: Is there any backend framework which uses the fetch API. That is, where requests are standard Request objects (https://developer.mozilla.org
by runarberg 3y ago
Follow-up question: Is there any backend framework which uses the fetch API. That is, where requests are standard Request objects (https://developer.mozilla.org/en-US/docs/Web/API/Request https://developer.mozilla.org/en-US/docs/Web/API/Request) and where you send (or return, or yield) standard Response objects (https://developer.mozilla.org/en-US/docs/Web/API/Response https://developer.mozilla.org/en-US/docs/Web/API/Response)?
I’m teaching a highschool kid web development and it would be very nice to be able to teach the same standard on the back end as we use on the front end.
- chrisweekly 3y agohttps://Remix.run https://Remix.run embraces web standards, it's exactly what you're looking for.
- lylejantzi3rd 3y agoIsn't that what node-fetch is for? https://www.npmjs.com/package/node-fetch https://www.npmjs.com/package/node-fetch
- runarberg 3y agoThe 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 }, ); });
- lolinder 3y agoI think Deno could be a good choice for that—it's an entire server side JavaScript runtime built around the idea of using web standards instead of server-specific code. In addition to using standard Request and Response objects in its built-in server framework, Deno's approach to dependencies and TypeScript lends itself really well to educational settings—with no compilation step and no package management step, it's as simple to get started with Deno server-side as it is to start with HTML/JS in the browser—just open up a text editor and start writing! https://deno.com/learn/api-servers https://deno.com/learn/api-servers
- runarberg 3y agoYes, this is exactly how I want to write my servers while teaching web-development. Only problem is it is kind of hard to justify teaching Deno when Node is so overwhelmingly used in the industry.
- lolinder 3y agoI think high school is too early to be thinking too hard about what is used in industry. I learned to program with Macromedia Flash, which was big at the time but was completely irrelevant by the time I actually was ready for my career. I don't regret it at all, though—it was perfect for me learning at the time, and taught me the skills that I've used to pick up dozens of different technologies since then. For education it's far more important to choose technologies that minimize the barrier to entry and allow someone to start learning meaningful skills quickly, rather than forcing them to slog through the instruction manual for an industrial-strength technology before they even understand the basics. We don't apologize for starting a beginner woodworker on a lathe rather than a CNC machine.
- runarberg 3y agoIndeed a very good point. Perhaps I’ll pick up Deno for my next set of students