Skip to content

Commit

Permalink
Merge branch 'main' into zip_attachment_example
Browse files Browse the repository at this point in the history
  • Loading branch information
schloerke authored Nov 17, 2023
2 parents d2d557e + 8cf3177 commit ea855e2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Suggests:
redoc,
rapidoc,
sf
RoxygenNote: 7.2.2
RoxygenNote: 7.2.3
Collate:
'async.R'
'content-types.R'
Expand Down
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
function(req[, res, ...]) {
...
req$argsQuery
req$argsPath
req$argsBody
...
}
```

### Cookies {#read-cookies}

Expand Down
2 changes: 0 additions & 2 deletions vignettes/tips-and-tricks.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,6 @@ function(req, res){
If you run this API locally and then visit the API in a web browser, you'll see your R session switch into debug mode when the request arrives, allowing you to look at the objects contained inside your `req` and `res` objects.


### Plumber Server

## Port Range

You can use [httpuv::randomPort()] to define a range of port for Plumber to pick from when running an API.
Expand Down

0 comments on commit ea855e2

Please sign in to comment.