![]() 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. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |