Skip to content

Commit

Permalink
Update docs with the request access simplification
Browse files Browse the repository at this point in the history
  • Loading branch information
jameslcarter committed Mar 10, 2024
1 parent 3280ef2 commit 3abdd65
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion website/docs/reference/request/condition-attribute.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ The condition can also be used to match based on query parameters:
"request": {
"method": "GET",
"route": "any/{myVar}",
"condition": "<#= Request.Query["foo"]?.ToString() == "bar" #>"
"condition": "<#= Request.Query["foo"] == "bar" #>"
},
"response": {
"body": "Hello!"
Expand Down
4 changes: 1 addition & 3 deletions website/docs/scripting/index.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Scripting

Every part of the mock file is scriptable, so you can add code to programatically generate parts of the template.
Every part of the mock file is scriptable, so you can add code to programmatically generate parts of the template.

Use C# code surrounded by ```<#=``` and ```#>```.

Expand All @@ -11,14 +11,12 @@ Although it pays off, in the other hand, the invalid JSON file may be a little h

:::


The mock code and generation will run for each request.

It's possible to access request data within the response template. In the same way, response data can be used within the callback request template.

The scripts are compiled and executed via [Roslyn](https://github.com/dotnet/roslyn/wiki/Scripting-API-Samples).


### Example
```json
{
Expand Down
20 changes: 14 additions & 6 deletions website/docs/scripting/request-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,20 @@ There is a ```Request``` object available to access request data.
"response": {
"status": "OK",
"body": {
"url": "<#= Request.Url?.ToString() #>",
"customerId": "<#= Request.Route["id"]?.ToString() #>",
"acceptHeader": "<#= Request.Header["Content-Type"]?.ToString() #>",
"queryString": "<#= Request.Query["dummy"]?.ToString() #>",
"requestBodyAttribute": "<#= Request.Body["address"]?[0]?.ToString() #>"
"url": "<#= Request.Url #>",
"customerId": "<#= Request.Route["id"] #>",
"acceptHeader": "<#= Request.Header["Content-Type"] #>",
"queryString": "<#= Request.Query["dummy"] #>",
"requestBodyAttribute": "<#= Request.Body["address"]?[0] #>"
}
}
}
```
```

The Request object has the following properties:

- `Url`: An instance of [`Uri`](https://learn.microsoft.com/dotnet/api/system.uri) class containing request URL data.
- `Route`: A string dictionary containing route parameters.
- `Header`: A string dictionary containing request headers.
- `Query`: A string dictionary containing query parameters.
- `Body`: A [JToken](https://www.newtonsoft.com/json/help/html/t_newtonsoft_json_linq_jtoken.htm) object containing request body data.

0 comments on commit 3abdd65

Please sign in to comment.