With a pokemon API example
Disclaimer: All opinions are my own
A while back I wrote about using Powershell’s handy Invoke-WebRequest
method and bypassing the certificate check, but there’s another useful Powershell method related to invoking web methods: Invoke-RestMethod
The full docs are here, but it’s very similar to Invoke-WebRequest
with the difference of what it shows you by default.
Let’s look at a couple of examples of PokeAPI.
When I run Invoke-WebRequest
on the PokeAPI:
Invoke-WebRequest https://pokeapi.co/api/v2/pokemon/ditto
I get back a response with a lot of information about the request, but not much information from the request

I can kind of see it embedded in the content, and if I’m not being too lazy I can see an easy way to pull that out and parse it.
(Invoke-WebRequest https://pokeapi.co/api/v2/pokemon/ditto).Content | ConvertFrom-json

But I’m a programmer and we’re inherently lazy. So let’s try the same thing with Invoke-RestMethod
Invoke-RestMethod https://pokeapi.co/api/v2/pokemon/ditto

And now I immediately have all of the content parsed and available.
This kind of representation is handy if you want to continue using the result to do further exploration like retrieving all of the details for the Pokemon’s species:
$pokemon = Invoke-RestMethod https://pokeapi.co/api/v2/pokemon/ditto;
Invoke-RestMethod $pokemon.species.url;

And there you have it — invoking a rest method with powershell. Happy powershelling!