fetch api javascript
JavaScript
fetch('http://example.com/songs')
.then(response => response.json())
.then(data => console.log(data))
.catch(err => console.error(err));fetch('http://example.com/movies.json')
.then((response) => {
return response.json();
})
.then((myJson) => {
console.log(myJson);
});fetch('http://example.com/movies.json')
.then((response) => {
return response.json();
})
.then((data) => {
console.log(data);
});
//Most API's will only allow you to fetch on their website.
//This means you couldn't run this code in the console on
// google.com because:
// 1. Google demands the fetch request be from https
// 2. open-notify's API blocks the request outside of their website
fetch('http://api.open-notify.org/astros.json')
.then(function(response) {
return response.json();
})
.then(function(json) {
console.log(json)
});
// Here is another example. A method (function) that
// grabs Game of Thrones books from an API ...
function fetchBooks() {
return fetch('https://anapioficeandfire.com/api/books')
.then(resp => resp.json())
.then(json => renderBooks(json));
}
function renderBooks(json) {
const main = document.querySelector('main')
json.forEach(book => {
const h2 = document.createElement('h2')
h2.innerHTML = `<h2>${book.name}</h2>`
main.appendChild(h2)
})
}
document.addEventListener('DOMContentLoaded', function() {
fetchBooks()
})
developer.mozilla.org
Also in JavaScript:
- Title
- javascript closure stack overflow
- Category
- JavaScript
- Title
- add table header dynamically in jquery
- Category
- JavaScript
- Title
- ExoPlayer with auto linking react native
- Category
- JavaScript
- Title
- angular event emitter
- Category
- JavaScript
- Title
- document delete element
- Category
- JavaScript
- Title
- count value a to b character javascript
- Category
- JavaScript
- Title
- angular generate component
- Category
- JavaScript
- Title
- add a slash to string in javascript
- Category
- JavaScript
- Title
- ES6: Use class Syntax to Define a Constructor Function
- Category
- JavaScript
- Title
- convert json to 2d array
- Category
- JavaScript
- Title
- javascript adding an array to an array
- Category
- JavaScript
- Title
- integer to array javascript
- Category
- JavaScript
- Title
- how to get the size of the window in javascript
- Category
- JavaScript
- Title
- compile angularjs template
- Category
- JavaScript
- Title
- get url params angular
- Category
- JavaScript
- Title
- create react app deployment heroku
- Category
- JavaScript
- Title
- convert object to json javascript
- Category
- JavaScript
- Title
- Heroku H10-App Crashed Error
- Category
- JavaScript
- Title
- how to convert string to int js
- Category
- JavaScript
- Title
- add readonly attribute jquery
- Category
- JavaScript
- Title
- how to access all images in a document javascript
- Category
- JavaScript
- Title
- html get elements by class
- Category
- JavaScript
- Title
- accept 2 values after decimal in angular forms
- Category
- JavaScript
- Title
- calling function from function object javascript
- Category
- JavaScript
- Title
- convert class object to json python
- Category
- JavaScript
- Title
- fizz buzz javascript
- Category
- JavaScript
- Title
- console.log in jsx
- Category
- JavaScript
- Title
- command to create react app
- Category
- JavaScript
- Title
- empty array js
- Category
- JavaScript
- Title
- chart.js radar chart
- Category
- JavaScript
- Title
- .map function
- Category
- JavaScript
- Title
- convert jquery to string
- Category
- JavaScript
- Title
- how to set height of material ui dialog react
- Category
- JavaScript
- Title
- go to another page javascript
- Category
- JavaScript
- Title
- how to use hooks react
- Category
- JavaScript
- Title
- focus js
- Category
- JavaScript
- Title
- check if javascript function is true
- Category
- JavaScript
- Title
- adding cors in angular
- Category
- JavaScript
- Title
- getboundingclientrect() javascript
- Category
- JavaScript
- Title
- add char in specific index stirng javascript
- Category
- JavaScript
- Title
- facebook integration in node.js
- Category
- JavaScript
- Title
- fsharp newtonsoft json deserialize
- Category
- JavaScript
- Title
- include jquery
- Category
- JavaScript
- Title
- chart.js line chart
- Category
- JavaScript
- Title
- indexof javascript
- Category
- JavaScript
- Title
- array length for boolean in javascript
- Category
- JavaScript
- Title
- add custom marker in react-mapbox-gl
- Category
- JavaScript
- Title
- enzyme test method
- Category
- JavaScript
- Title
- debug node
- Category
- JavaScript
- Title
- How to check whether a checkbox is checked in jQuery?
- Category
- JavaScript
- Title
- fonction fleche javascript
- Category
- JavaScript
- Title
- append to array js
- Category
- JavaScript
- Title
- cache buster in angular application
- Category
- JavaScript
- Title
- async iife
- Category
- JavaScript
- Title
- if clicked outside of div jquery
- Category
- JavaScript
- Title
- add select option jquery
- Category
- JavaScript
- Title
- box shadow javascript style change
- Category
- JavaScript
- Title
- ellipsis javascript
- Category
- JavaScript
- Title
- how to export module in node js
- Category
- JavaScript
- Title
- https package node post request
- Category
- JavaScript
- Title
- how to create seeds in sequelise
- Category
- JavaScript
- Title
- fixed header on scroll vuejs
- Category
- JavaScript
- Title
- add val to array jquery
- Category
- JavaScript
- Title
- copy to clipboard javascript
- Category
- JavaScript
- Title
- arrays javascript
- Category
- JavaScript
- Title
- after click text editior open in javascript
- Category
- JavaScript
- Title
- extend react.component
- Category
- JavaScript
- Title
- group all items with same name js
- Category
- JavaScript
- Title
- discord js channel count
- Category
- JavaScript
- Title
- get youtube video id from url javascript
- Category
- JavaScript
- Title
- busca binária em javascript
- Category
- JavaScript
- Title
- create bottom navigation bar react native
- Category
- JavaScript
- Title
- javascript check if two date are ugual
- Category
- JavaScript
- Title
- bind jquery trough name
- Category
- JavaScript
- Title
- flowjs attributes
- Category
- JavaScript
- Title
- add image in react native
- Category
- JavaScript
- Title
- how to count click events javascript
- Category
- JavaScript
- Title
- add elements to an array with splice
- Category
- JavaScript
- Title
- componentwillreceiveprops hooks
- Category
- JavaScript
- Title
- get attribute value jquery
- Category
- JavaScript
- Title
- bootstrap 4 hide modal via javascript
- Category
- JavaScript
- Title
- ascii to char in javascript
- Category
- JavaScript
- Title
- export function javascript
- Category
- JavaScript
- Title
- check element exist in jquery
- Category
- JavaScript
- Title
- difference between e.preventdefault and e.stoppropagation and return false
- Category
- JavaScript
- Title
- how to send a command in js
- Category
- JavaScript
- Title
- iframe loader jquery
- Category
- JavaScript
- Title
- get date one week from now javascript
- Category
- JavaScript
- Title
- add and remove class in jquery
- Category
- JavaScript
- Title
- add month date now javascript
- Category
- JavaScript
- Title
- how to use local static images in svelte
- Category
- JavaScript
- Title
- if statemnt shorthand js without else
- Category
- JavaScript
- Title
- javascript ceiling
- Category
- JavaScript
- Title
- firebase cloud functions send email
- Category
- JavaScript
- Title
- client side redirect javascript
- Category
- JavaScript
- Title
- change web page on button click
- Category
- JavaScript
- Title
- check array values equal js
- Category
- JavaScript
- Title
- angular interview questions
- Category
- JavaScript
- Title
- change title react
- Category
- JavaScript
- Title
- get page resolution jquery
- Category
- JavaScript