July 2018
Beginner
552 pages
13h 18m
English
Interacting with REST APIs is rather easy in PowerShell; the Invoke-RestMethod cmdlet does all the heavy lifting for you. Let's view the four example calls, Create, Read, Update, and Delete, with our own API in the following example:
$jsonBody = @{ Name = 'testfile.txt' Content = 'This is almost too easy'} | ConvertTo-Json$jsonBodyUpdate = @{ Name = 'testfile.txt' Content = 'It works like a charm'} | ConvertTo-Json# CreateInvoke-RestMethod -Method Post -Uri http://localhost:8080/files -Body $jsonBody -ContentType application/json# Read - Invoke-RestMethod converts from JSON automatically# All filesInvoke-RestMethod -Method Get -Uri http://localhost:8080/files# Specific fileInvoke-RestMethod -Method Get -Uri ...Read now
Unlock full access