When running without errors it outputs something like the following to stdout:
IpInfo(X1.X2.X3.X4)
fetch("https://jsonip.com", {headers: { "Accept": "application/json" }})
.catch(err => { status: err })
.then(resp => resp.json())
.then(console.log)
Except that this JS doesn't check the form of the JSON returned conforms to the expected structure.
In async/await code structure it would be like this:
const onFailure = err => { status: err }
const resp = await fetch("https://jsonip.com", {headers: { "Accept": "application/json" }}).catch(onFailure)
const json = resp.json()
console.log(json)
Again there is not decoding the response body to check it has the structure the client expects.
import * as t from 'io-ts'
const IpInfo = t.type({
status: t.number
})
type IpInfo = t.TypeOf<typeof IpInfo>
const onFailure = err => { status: err }
const resp = await fetch("https://jsonip.com", {headers: { "Accept": "application/json" }}).catch(onFailure)
const json = resp.json()
const result = IpInfo.decode(json)
console.log(result)