Sending an HTTP request in Vue.js
Sending HTTP requests to a RESTFul service if you are developing a modern web application is trivial. There are HTTP client libraries such as api-sauce
, super-agent
, and axios
. Do you know that JavaScript itself has a native API for sending HTTP requests? Yes, and that is the Fetch API.
The Fetch API is available in JavaScript and TypeScript. However, it only works in modern browsers and will not work when you load your application in older browsers. Not only that, but the Fetch API can also be too verbose when using its APIs to send a request, in my opinion. I would prefer an HTTP client library with an abstraction to not write extra code such as res.json()
, headers
, or the property
method. In that case, we will be using Axios as our HTTP client library.
Axios is a promise-based HTTP client library for the browser and server-side Node.js app. It is simple to use and also supports older browsers. We will install Axios together with Day.js, which...