Talking to the Web
Read a web API as objects, download files and check that a site is up.
Updated
The Web
- APIs as Objects: `Invoke-RestMethod` (Journeyman): Invoke-RestMethod asks a web API for data and turns its JSON answer into objects, so a weather forecast arrives ready for Select-Object, Where-Object and the rest of the pipeline, and query parameters after a ? in the address ask for exactly what you want.
- Pages and Downloads: `Invoke-WebRequest` (Journeyman): Invoke-WebRequest gives you the whole answer from a web address, not only its data, so you can read the status code that says whether a page is there, read the headers that describe it, and save what it sends as a file with -OutFile.
Exercise: Today's Weather Report
- Exercise: Today's Weather Report (Journeyman): Answer a running club's three morning questions (will it rain, how warm will it be, when can we run dry) from saved copies of a real weather API's answers, with Invoke-RestMethod's objects, query parameters and the pipeline, saving each answer as a small report that a Pester check reads.