Note: This site is currently "Under construction". I'm migrating to a new version of my site building software. Lots of things are in a state of disrepair as a result (for example, footnote links aren't working). It's all part of the process of building in public. Most things should still be readable though.

Get Data From An API With windowfetch

This is how I'm pulling data from a basic API:

Code

function getCurrentState() {
    let fetchUrl = 'https://example.com/some-api.json'
    return window.fetch(fetchUrl)
    .then(response => response.json())
    .then(response => console.log(response.someKey))
}

getCurrentState()

This works with a promise which I'm not totally sure about how you would use it with a return, but this gets you there for a start.

The payload from the api should be:

Code

{ someKey: "some Value"}