9 Tweets Apr 13, 2023
Different ways to call API in JavaScript
Thread πŸ§΅πŸ‘‡
There are multiple ways to call APIs in JavaScript.
πŸ‘‰ fetch API
πŸ‘‰ XMLHttpRequest
πŸ‘‰ Axios
πŸ‘‰ Got
πŸ‘‰ node-fetch
πŸ“Œ fetch API
It is an asynchronous web API that comes with native JavaScript and returns the data in the form of promises.
πŸ“Œ XMLHttpRequest
It’s another Web API that lets you communicate with the server via a REST API endpoint to fetch data and then show it to the user without refreshing the page.
Despite its name, the XMLHttpRequest API is not limited to XML and works with JSON data too.
πŸ“Œ Axios
Axios is an open-source, promise-based HTTP client. It uses JavaScript’s promises to send HTTP requests and manage their responses.
πŸ“Œ Got
Got is a lighter, human-friendly powerful HTTP request library explicitly designed to work with Node.js. It supports pagination, RFC-compliant caching, makes an API request again if it fails, supports cookies out of the box, and more.
πŸ“Œ node-fetch
It is a lightweight npm package that lets you use fetch API in Node.js. You can use promise-chaining and async functions to work with it.
We have discussed it in detail in one of our pieces that you can find here. β†’ rapidapi.com
That’s all for now!
Follow @Rapid_API for more exclusive content. πŸ™

Loading suggestions...