You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Is there a way to create a http server based on Fetch API? (Request, Response, Headers, ...) #4174
If not, how to properly use the http package and convert IncomingMessage to Request and use the Response to send response in the handler of createServer function?
Node.js version
18+
Example code
Here is my naive implementation of the serve function. I have several quetions about it:
will such an implementation work fast enough? Or there are clear indicators of speed drawdown
can anyone suggest what use cases i'm missing (other than error handling)?
If not, how to properly use the http package and convert IncomingMessage to Request and use the Response to send response in the handler of createServer function?
the "Request" you mentioned in the issue
This seems like a pretty nice thing for Node.js to have. I'm trying to write these conversion methods myself but it's easy to mis something 😅 could this be a rework of createServer
Stumbled upon this while looking for solutions on how to use itty-router with node.js.
Found this so far https://www.npmjs.com/package/@whatwg-node/server ... but it says it ponyfills, which is better than polyfilling, but it still does too much magic for my liking
Reacted by Dmitriy Petrov, Julian Cataldo and Quetzal Rivera
It seems there has been no activity on this issue for a while, and it is being closed in 30 days. If you believe this issue should remain open, please leave a comment.
If you need further assistance or have questions, you can also search for similar issues on Stack Overflow.
Make sure to look at the README file for the most updated links.
It seems there has been no activity on this issue for a while, and it is being closed in 30 days. If you believe this issue should remain open, please leave a comment.
If you need further assistance or have questions, you can also search for similar issues on Stack Overflow.
Make sure to look at the README file for the most updated links.
I'm closing this issue due to inactivity. At the current time, the only comments resolving the stalebot weren't relevant to resolving this issue, so I'll assume this is still stale.
To answer the question, no, there is not currently a way to write a server via the Fetch API, although you can always implement one :-).
It would be great for the ecosystem to (please) reconsider this, maybe under a standarized Fetch Server proposal together with WinterTC https://wintertc.org/
Nowadays pretty much all modern frameworks and libraries use fetch-based APIs and objects (Request, Response, Headers, etc) and there is also a little overhead (from microseconds to a few ms depending on the implementation) when converting from Node's Req/Res to fetch and vice-versa:
Incoming TCP socket
→ Node http.IncomingMessage / ServerResponse
→ Adapt to Fetch Request
→ (App logic)
→ Fetch Response
→ Adapt back to Node response
→ Socket write
Reacted by tvandenbrugghen-stratalis and Quetzal Rivera
Activity
preveen-stack commentedon Jun 13, 2023
Can you show how the request looks like
krutoo commentedon Jun 13, 2023
@preveen-stack not quite understand what the request means?
preveen-stack commentedon Jun 13, 2023
krutoo commentedon Jun 13, 2023
@preveen-stack global Node.js constructors Request and Response from Fetch API:
jensmeindertsma commentedon Oct 28, 2023
This seems like a pretty nice thing for Node.js to have. I'm trying to write these conversion methods myself but it's easy to mis something 😅 could this be a rework of
createServerbra1nDump commentedon Nov 8, 2023
Stumbled upon this while looking for solutions on how to use itty-router with node.js.
Found this so far https://www.npmjs.com/package/@whatwg-node/server ... but it says it ponyfills, which is better than polyfilling, but it still does too much magic for my liking
github-actions commentedon May 7, 2024
It seems there has been no activity on this issue for a while, and it is being closed in 30 days. If you believe this issue should remain open, please leave a comment.
If you need further assistance or have questions, you can also search for similar issues on Stack Overflow.
Make sure to look at the README file for the most updated links.
krutoo commentedon May 7, 2024
@bra1nDump
@whatwg-node/serveris great, thanksBut it looks like a little tricky solution and i dont think this is get great performance
github-actions commentedon Nov 28, 2024
It seems there has been no activity on this issue for a while, and it is being closed in 30 days. If you believe this issue should remain open, please leave a comment.
If you need further assistance or have questions, you can also search for similar issues on Stack Overflow.
Make sure to look at the README file for the most updated links.
krutoo commentedon Nov 28, 2024
Are there any plans to add builtin utilities for creating an HTTP server on Fetch API in Node.js?
ydvkarthik commentedon Dec 12, 2024
avivkeller commentedon Apr 7, 2025
I'm closing this issue due to inactivity. At the current time, the only comments resolving the stalebot weren't relevant to resolving this issue, so I'll assume this is still stale.
To answer the question, no, there is not currently a way to write a server via the Fetch API, although you can always implement one :-).
mb21 commentedon Sep 27, 2025
Is this still not even under consideration? Nowadays, pretty much every JS-runtime except Node supports this: see https://blog.val.town/blog/the-api-we-forgot-to-name/ or https://marvinh.dev/blog/modern-way-to-write-javascript-servers/
itsjavi commentedon Jan 3, 2026
It would be great for the ecosystem to (please) reconsider this, maybe under a standarized Fetch Server proposal together with WinterTC https://wintertc.org/
Nowadays pretty much all modern frameworks and libraries use fetch-based APIs and objects (Request, Response, Headers, etc) and there is also a little overhead (from microseconds to a few ms depending on the implementation) when converting from Node's Req/Res to fetch and vice-versa: