Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update parameters collision doc #923

Merged
merged 3 commits into from
Nov 17, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion vignettes/routing-and-input.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,21 @@ Alternatively, `echo {"id":123, "name": "Jennifer"} > call.json & curl --data @c

As demonstrated above, the raw request body is made available as `req$bodyRaw` and parsed request body is available as `req$body`.

If multiple parameters are matched to the endpoint formals, an error will be thrown. Due to the nature of how multiple values can be matched to the same argument, it is recommended that `POST` endpoints have a function definition that only accepts the formals `req`, `res`, and `...`. If the endpoint arguments are to be processed like a list, they are available at `req$argsBody`, with all arguments at `req$args`. `req$args` is a combination of `list(req = req, res = res)`, `req$argsPath`, `req$argsBody`, and `req$argsQuery`.
#### Named parameters collision note

Only the first matched formal arguments are passed automatically to the endpoint during execution. Duplicates are dropped. Query parameters have priority over path parameters, then finally, body parameters are matched last.

While not required, it is recommended that endpoints have a function definition that only accepts the formals `req`, `res`, and `...` to avoid duplicates. If the endpoint arguments are to be processed like a list, they are available at `req$argsBody`, with all arguments at `req$args`. `req$args` is a combination of `list(req = req, res = res)`, `req$argsPath`, `req$argsBody`, and `req$argsQuery`.

```{r, echo=FALSE, results='asis'}
schloerke marked this conversation as resolved.
Show resolved Hide resolved
function(req[, res, ...]) {
...
req$argsQuery
req$argsPath
req$argsBody
...
}
```

### Cookies {#read-cookies}

Expand Down
Loading