Facebook Twitter Instagram
    Monday, May 23
    Trending
    • New floods in eastern South Africa displace more than 300
    • Count Number of Element Occurrences in JavaScript Array
    • Will Smith Envisioned His Career Slipping Away While On Psychedelics Before Oscars Slap
    • ‘I Was Not Ready To Go’: Tina Reflects On Her Game-Ending All Stars Injury
    • Best Characters From the Show, Ranked
    • Justin Thomas wins the PGA Championship with record comeback
    • ‘Nadal is always favourite here’
    • Agora rebrands to Kojo as it expands construction procurement
    Facebook Twitter Instagram Pinterest VKontakte
    Swave Digest
    • Home
    • World News
    • Technology
      • Smartphones
      • Computers
      • Programming
      • Automobiles
    • Entertainment
      • Music
      • Anime
      • Movies
    • Sports
      • Football
      • Basketball
      • Tennis
    • Business
      • Crypto
      • Stocks
      • NFT
    • Lifestyle
      • Fashion
      • Health
      • Travel
    • Shop
    Swave Digest
    Home»Technology»Programming»How to Call a REST Method From Powershell | by Brian Olson | May, 2022
    Programming

    How to Call a REST Method From Powershell | by Brian Olson | May, 2022

    Swave DigestBy Swave DigestMay 10, 2022No Comments1 Min Read
    Facebook Twitter Pinterest LinkedIn Tumblr Email
    How to Call a REST Method From Powershell | by Brian Olson | May, 2022 0*P1rOu6ZgsKLlbqJ7?resize=1024&w=1024
    Share
    Facebook Twitter LinkedIn Pinterest Email

    With a pokemon API example

    How to Call a REST Method From Powershell | by Brian Olson | May, 2022 0*P1rOu6ZgsKLlbqJ7
    Photo by Pixabay from Pexels

    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

    How to Call a REST Method From Powershell | by Brian Olson | May, 2022 1*GLlgJgKehyCYfAP OhFW9g

    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
    How to Call a REST Method From Powershell | by Brian Olson | May, 2022 1*5qPT976MNsGe7pkiuafUig

    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
    How to Call a REST Method From Powershell | by Brian Olson | May, 2022 1*c0DLhD0lJCkRu4Uzd EB4Q

    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;
    How to Call a REST Method From Powershell | by Brian Olson | May, 2022 1*st6DOA PttACUf0W0PNs7g

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

    2022 brian call from how may method olson powershell programming rest
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Swave Digest
    • Website
    • Twitter
    • Pinterest

    Related Posts

    Count Number of Element Occurrences in JavaScript Array

    May 23, 2022

    Best Characters From the Show, Ranked

    May 23, 2022

    How Shiva Can Help Corporations Build Unicorns In Revolutionary Trends

    May 23, 2022

    Source Control Your AWS CloudFormation Templates With GitHub | by Sarah Lean | May, 2022

    May 23, 2022
    Add A Comment

    Leave A Reply Cancel Reply

    Twitter Instagram Pinterest
    • Home
    • Privacy Policy
    • Terms & Conditions
    • Contact Us
    © 2022 Swave Digest. All Rights Reserved.

    Type above and press Enter to search. Press Esc to cancel.