This content originally appeared on DEV Community and was authored by Buddhadeb Chhetri
Javascript API Calls
XML HTTP Request
- All modern browsers support the XMLHttpRequest object to request data from a server.
- It works on the oldest browsers as well as on new ones.
- It was deprecated in ES6 but is still widely used.
var request = new XMLHttpRequest();
request.open('GET','https://jsonplaceholder.typicode.com/users')
request.send();
request.onload =() =>{
console.log(JSON.parse(request.response));
}
Fetch API
- The Fetch API provides an interface for fetching resources including across the network in an asynchronous.
- It returns a Promise.
- It is an object which contains a single value either a Response or an Error that occurred.
- .then() tells the program what to do once Promise is completed.
fetch('https://jsonplaceholder.typicode.com/users')
.then(response=>{
return response.json();})
.then(data=>{
console.log(data);
})
Axios
- It is an open-source library for making HTTP requests.
- It works on both Browsers and Node js.
- It can be included in an HTML file by using an external CDN.
- It also returns promises like fetch API
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
axios.get('https://jsonplaceholder.typicode.com/users')
.then(response =>{
console.log(response.data)})
JQuery AJAX
- It performs asynchronous HTTP requests.
- Uses $.ajax() method to make the requests.
- Ability to send GET and POST requests
- Ability to Load JSON, XML, HTML or Scripts
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
$(document).ready(function(){
$.ajax({
url:"https://jsonplaceholder.typicode.com/users",
type:"GET",success:function(result){
console.log(result);
}
})
})
This content originally appeared on DEV Community and was authored by Buddhadeb Chhetri
Print
Share
Comment
Cite
Upload
Translate
Updates
There are no updates yet.
Click the Upload button above to add an update.

APA
MLA
Buddhadeb Chhetri | Sciencx (2021-08-07T18:18:56+00:00) API Calls. Retrieved from https://www.scien.cx/2021/08/07/api-calls/
" » API Calls." Buddhadeb Chhetri | Sciencx - Saturday August 7, 2021, https://www.scien.cx/2021/08/07/api-calls/
HARVARDBuddhadeb Chhetri | Sciencx Saturday August 7, 2021 » API Calls., viewed ,<https://www.scien.cx/2021/08/07/api-calls/>
VANCOUVERBuddhadeb Chhetri | Sciencx - » API Calls. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/08/07/api-calls/
CHICAGO" » API Calls." Buddhadeb Chhetri | Sciencx - Accessed . https://www.scien.cx/2021/08/07/api-calls/
IEEE" » API Calls." Buddhadeb Chhetri | Sciencx [Online]. Available: https://www.scien.cx/2021/08/07/api-calls/. [Accessed: ]
rf:citation » API Calls | Buddhadeb Chhetri | Sciencx | https://www.scien.cx/2021/08/07/api-calls/ |
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.