How to call rest API from Vue js?

Sharad Jaiswal
Sharad Jaiswal

Posted On: Feb 12, 2020

 

We can use various HTTP libraries to call REST Api's from Vue JS. One of the popular libraries is Axios. It simple to use and lightweight. To include it in your project, execute the following command.

npm install axios --save

Implementing GET method using Axios in Vue JS

axios({ method: "GET", "URL": "https://httpbin.org/ip" }).then(result => {
                this.ip = result.data.origin;
            }, error => {
                console.error(error);
            });


We can send an HTTP request using Axios with a promise. If the request is successful, we’ll get the result.

    Related Questions

    Please Login or Register to leave a response.

    Related Questions

    Programming

    How to Crack HTML5 Interview Questions

    HTML5 is the latest and one of the most advanced standards of HTML. It is not a programming language actually but it is one of the most important components of modern day web application. This is used..

    Programming

    How to you validate null or empty value in JavaScript?

    Checking value is null or empty in Javascript..

    Programming

    A set of Interview questions for HR Position

    In the ideal hierarchy of an organizational structure, HR plays a very important role. No one can simply rely upon a technical, Administration and other segments only. HR stands for Human Resource man..