=====curl / wget in der Powershell - Testen von ORDS Webservices in der Powershell über die Console=====
Unter Linux läßt sich eine Webseite mit [[https://ss64.com/bash/curl.html|curl]] oder [[https://www.gnu.org/software/wget/|wget]] sehr einfach abfragen.
In der Powershell können dafür zwei Aufruf für das Testen von REST Services aufgerufen werden:
* Invoke-WebRequest (iwr/curl/wget) => Alle Details , gut zum Debug
* Invoke-RestMethod (irm) => Genau die Anwort des Service, gut für die Integration von REST Aufrufen in eigene Skripte
===Invoke-WebRequest===
curl/wget sind als Alias für das cmdlet "Invoke-WebRequest" hinterlegt.
Beispiel für einen sehr einfachen REST Aufruf mit GET um die Version der API abzufragen:
Invoke-WebRequest -Uri http://127.0.0.1:9090/ords/gpi/api/version/
StatusCode : 200
StatusDescription : OK
Content : {"version":"1"}
RawContent : HTTP/1.1 200 OK
Transfer-Encoding: chunked
Content-Type: application/json
Date: Sun, 21 Oct 2018 16:31:26 GMT
ETag: "Aj/F2I7I9tJv0HnVQVyQNka0ylNOD1DCJwMt77AHjZzC59+Udn0CKuCUb0NwiXOcT3nwWkl0nUj+Pyc...
Forms : {}
Headers : {[Transfer-Encoding, chunked], [Content-Type, application/json], [Date, Sun, 21 Oct 2018 16:31:26 GMT], [ETag,
"Aj/F2I7I9tJv0HnVQVyQNka0ylNOD1DCJwMt77AHjZzC59+Udn0CKuCUb0NwiXOcT3nwWkl0nUj+Pyc4zMU0Ow=="]}
Images : {}
InputFields : {}
Links : {}
ParsedHtml : mshtml.HTMLDocumentClass
RawContentLength : 15
===Invoke-RestMethod===
In der Powershell steht einem dafür **"Invoke-RestMethod"** bzw als alias **"irm"** zur Verfügung.
Beispiel für einen sehr einfachen REST Aufruf mit GET um die Version der API abzufragen:
Invoke-RestMethod -Uri http:\\localhost:9090
version
-------
1
==== REST Service abfragen ====
Beim Abfragen eines Webservice, zum Beispiel vom ORDS => [[prog:ords_rest_service|Oracle ORDS 3.0 REST API nativ verwenden]] ist die Verwendung dieses Befehls sehr praktisch, ein Json Record wird gleich als Tabelle dargestellt.
irm -Uri http://127.0.0.1:9090/ords/gpi/api/version/
version
-------
1
----
==== Optionen===
===Invoke-RestMethod bzw. irm===
help irm
NAME
Invoke-RestMethod
SYNTAX
Invoke-RestMethod [-Uri] [-Method {Default | Get | Head | Post | Put | Delete | Trace | Options | Merge | Patch}] [-UseBasicParsing] [-WebSession ] [-SessionVariable ]
[-Credential ] [-UseDefaultCredentials] [-CertificateThumbprint ] [-Certificate ] [-UserAgent ] [-DisableKeepAlive] [-TimeoutSec ] [-Headers ]
[-MaximumRedirection ] [-Proxy ] [-ProxyCredential ] [-ProxyUseDefaultCredentials] [-Body
===Invoke-WebRequest bzw. curl/wegt===
help curl
NAME
Invoke-WebRequest
SYNTAX
Invoke-WebRequest [-Uri] [-UseBasicParsing] [-WebSession ] [-SessionVariable ] [-Credential ] [-UseDefaultCredentials] [-CertificateThumbprint ]
[-Certificate ] [-UserAgent ] [-DisableKeepAlive] [-TimeoutSec ] [-Headers ] [-MaximumRedirection ] [-Method {Default | Get | Head | Post | Put | Delete | Trace |
Options | Merge | Patch}] [-Proxy ] [-ProxyCredential ] [-ProxyUseDefaultCredentials] [-Body
----
==== Quellen ====
* https://docs.microsoft.com/en-us/powershell/module/Microsoft.PowerShell.Utility/Invoke-RestMethod?view=powershell-3.0
* https://docs.microsoft.com/en-us/powershell/module/Microsoft.PowerShell.Utility/invoke-webrequest?view=powershell-3.0