You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm building an API service for my lab, and I'd like to implement either a PATCH or PUT call to modify an internal object for tracking purposes. Essentially the object is one large Hashtable. In my API Patch or Put call, I want to insert a new entry to this Hashtable, which I'll use the .Add(key, value) method. Well, when testing this in operation, the $Webevent.Data property is empty. Here is an example:
To invoke this, I'm using the following Invoke-RestMethod call:
# PATCH callInvoke-RestMethod-uri http://localhost:8080/api/endpoint -Method Patch -Body @{name="name1"; value="value1"}
# Returns:
Name Value
---------# PUT callInvoke-RestMethod-uri http://localhost:8080/api/endpoint -Method Put -Body @{name="name1"; value="value1"}
# Returns:
Name Value
---------# POST callInvoke-RestMethod-uri http://localhost:8080/api/endpoint -Method Post -Body @{name="name1"; value="value1"}
# Returns:
Name Value
---------
name1 value1
When I examine $Webevent when either PATCH or PUT is called, Data is empty:
Okay, after a bit more testing, it appears that my Invoke-RestMethod was not right. Invoke-RestMethod isn't converting the body from Hashtable to JSON, and I need to then also pass -ContenType "application/json". So, this call achieves what I need:
Invoke-RestMethod-uri http://localhost:8080/api/endpoint -Method Patch -Body (@{name="name1"; value="value1"} |ConvertTo-Json) -ContentType "application/json"# Returns:
Name Value
---------
name1 value1
I'll implement $Webevent.ContentType validation in the route I'm adding to ensure the caller includes that correctly. This API endpoint will only process and handle JSON content, nothing else.
Question
I'm building an API service for my lab, and I'd like to implement either a PATCH or PUT call to modify an internal object for tracking purposes. Essentially the object is one large Hashtable. In my API Patch or Put call, I want to insert a new entry to this Hashtable, which I'll use the
.Add(key, value)
method. Well, when testing this in operation, the$Webevent.Data
property is empty. Here is an example:To invoke this, I'm using the following Invoke-RestMethod call:
When I examine
$Webevent
when either PATCH or PUT is called,Data
is empty:Is this a bug? Am I using this HTTP method correctly?
PS version:
7.4.5
Pode version:
2.11.0
The text was updated successfully, but these errors were encountered: