The fetch() implementation is based on Undici, a new fast, reliable, and spec-compliant HTTP/1.1 client that is now bundled in Node.js core.This experimental core feature is the first step in that conversation, and it gives you an opportunity to try it out and get involved in the conversation. There is a lively ongoing conversation in the community about how to evolve Node’s HTTP stack in a way that’s familiar to client developers, but also works with the server programming model, how to move past the limitations of the current HTTP model that’s part of the core, and how to support HTTP/2-3 without over-burdening the user.There are two main reasons you may want to consider trying out fetch() in Node.js: The good part about fetch() being standardized is that most existing resources that pertain to the browser version will also work the same in the Node.js implementation, and there are a lot of great resources out there! Why should you care? Putting these together, here is a trivial example: const res = await fetch ( '' ) Response class - represents an incoming response instance.Request class - represents an outbound request instance.Headers class - deal with HTTP request/response headers instance.fetch() - the entry point used to initiate requests.That’s why the addition of fetch() to Node.js is an exciting step toward a more standard HTTP stack across devices and platforms.Īt its core, the API comprises of four interfaces One of the things that have held developers back is the relatively recent addition of this API to some browsers (looking at you, Android). To those coming from the browser world, it is similar to XMLHttpRequest, but standardized and with an expanded and more flexible feature set. It’s a promise-based client that supports many high-level HTTP features, while also focusing on the most common scenario: sending simplified HTTP requests. The fetch() API provides a WHATWG standardized interface for fetching resources, usually over HTTP. This post explores the fetch() API and why this is an important addition you should consider using (one of the reasons rhymes with schmer-formance). The good news is that going forward, an additional module will not be needed, as Node.js core will now support the API. So much so that the node-fetch module exists solely to backfill this functionality in Node.js. Node.js v17.5 introduces support for fetch() – a popular cross-platform HTTP client API that works in browsers and Web/Service Workers – as an experimental core feature.įetch() support has been a long-requested addition by many, who want to write cross-platform HTTP request code and are familiar with the fetch() API shape and call patterns.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |