Skip to main content

HTTP Client

The Wing standard library comes with HTTP support.

In this example we’ll use it to issue a simple HTTP request.

main.w
bring http;
bring cloud;

struct Pokemon {
id: num;
name: str;
order: num;
weight: num;
}

new cloud.Function(inflight () => {
let x = http.get("https://pokeapi.co/api/v2/pokemon/ditto");

// response status
log(x.status);

// parse string response as a JSON object
let data = Json.parse(x.body);

// cast JSON response into struct
let ditto = Pokemon.fromJson(data);
log(ditto.name);
});
Wing console output
# Run locally with wing console
200
ditto