Fake API Source
Do visit the website to get more info on the available resources to request.
http://jsonplaceholder.typicode.com/
JavaScript Fetch Example
To easily fetch a resource from an external API in JavaScript you can use "fetch" method like below. In this example, it's fetching a post from a fake API and upon getting the result it's parsed into JSON and then finally logged into the console after passing it again from the JavaScript promise.
fetch('https://jsonplaceholder.typicode.com/posts/1') .then((response) => response.json()) .then((json) => console.log(json));
Output
Now when you look at the "console.log", the output of the response will have 100 objects like below.
[ { id: 1, title: '...' /* ... */ }, { id: 2, title: '...' /* ... */ }, { id: 3, title: '...' /* ... */ }, /* ... */ { id: 100, title: '...' /* ... */ }, ];
Leave a reply