Skip to content

Commit

Permalink
#284: Update docs for using JSON payloads on PS4/5
Browse files Browse the repository at this point in the history
  • Loading branch information
Badgerati committed Jun 26, 2019
1 parent 594375e commit f5921d5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 3 additions & 0 deletions docs/Functions/Core/Route.md
Expand Up @@ -86,6 +86,9 @@ server {
}
```

!!! important
On PowerShell 4 and 5, referencing JSON data on `$event.Data` must be done as `$event.Data.Key`. This also works in PowerShell 6+, but you can also use `$event.Data['Key']` on PowerShell 6+.

### Example 5

The following example sets up a static route of `/assets` using the directory `./content/assets`. In the `home.html` view if you reference the image `<img src="/assets/images/icon.png" />`, then Pode will get the image from `./content/assets/images/icon.png`.
Expand Down
5 changes: 4 additions & 1 deletion docs/Tutorials/Routes/Overview.md
Expand Up @@ -59,7 +59,7 @@ server {
param($s)
# get the user
$user = Get-DummyUser -UserId $s.Data['userId']
$user = Get-DummyUser -UserId $s.Data.userId
# return the user
json @{
Expand All @@ -79,6 +79,9 @@ Invoke-WebRequest -Uri 'http://localhost:8080/users' -Method Post -Body '{ "user
!!! important
The `ContentType` is required as it informs Pode on how to parse the requests payload. For example, if the content type were `application/json`, then Pode will attempt to parse the body of the request as JSON - converting it to a hashtable.

!!! important
On PowerShell 4 and 5, referencing JSON data on `$s.Data` must be done as `$s.Data.userId`. This also works in PowerShell 6+, but you can also use `$s.Data['userId']` on PowerShell 6+.

## Query Strings

The following is an example of using data from a request's query string. To retrieve values from the query string you can use the `.Query` hashtable on the supplied web-session to a route's logic. This example will return a user based on the `userId` supplied:
Expand Down

0 comments on commit f5921d5

Please sign in to comment.