Let’s assume you are invited to the 37th birthday of a friend. What can you put on the birthday card? Try this:
PS> Invoke-RestMethod -Uri http://numbersapi.com/37 -UseBasicParsing
37 is the number of plays William Shakespeare is thought to have written (counting Henry IV as three parts).
Just replace the number in the URL to whatever number you need facts for. This is a great example of how easy it is to consume REST web services with PowerShell.
Invoke-RestMethod is always the smarter option. Sometimes examples use Invoke-WebRequest instead. With the latter you need to manually extract the information from the received values and convert it to the correct format. That’s what Invoke-RestMethod does for free:
PS> (Invoke-WebRequest -Uri http://numbersapi.com/37 -UseBasicParsing).Content
37 is the cost in cents of the Whopper Sandwich when Burger King first introduced it in 1957.
ReTweet this Tip!
Powered by IDERA