Skip to content

Add options argument to req.reply #1923

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion node.js/best-practices.md
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ Internally the [timestamp](events#timestamp) is a JavaScript `Date` object, that

When returning [Media Data](../guides/providing-services#serving-media-data) from a custom `READ`, `action`, or `function` handler, content information can be configured as part of the handlers result object.

Ideally, handlers use [`req.reply`](events#req-reply-results), calling it with an instance of [stream.Readable](https://nodejs.org/api/stream.html#class-streamreadable). Include options to specify content disposition headers:
Ideally, handlers use [`req.reply`](events#req-reply), calling it with an instance of [stream.Readable](https://nodejs.org/api/stream.html#class-streamreadable). Include options to specify content disposition headers:

```js
srv.on('READ', 'Books', (req, next) => {
Expand Down
13 changes: 9 additions & 4 deletions node.js/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ Additional note about OData: For requests that are part of a changeset, the even



Class `cds.Request` extends [`cds.Event`] with additional features to represent and deal with synchronous requests to services in [event handlers](./core-services#srv-handle-event), such as the [query](#query), additional [request parameters](#params), the [authenticated user](#user), and [methods to send responses](#req-reply-results).
Class `cds.Request` extends [`cds.Event`] with additional features to represent and deal with synchronous requests to services in [event handlers](./core-services#srv-handle-event), such as the [query](#query), additional [request parameters](#params), the [authenticated user](#user), and [methods to send responses](#req-reply).


[Router]: https://expressjs.com/en/4x/api.html#router
Expand Down Expand Up @@ -362,15 +362,19 @@ It's available for CRUD events and bound actions.



### req. reply (results) {.method}
### req. reply () {.method}

```tsx
function req.reply (
results : object | object[] | string | number | true | false | null
results : object | object[] | string | number | true | false | null,
options? : {
mimetype? : string
filename? : string
}
)
```

Stores the given argument in `req.results`, which is subsequently sent back to the client, rendered in a protocol-specific way.
Stores the first argument in `req.results`, which is subsequently sent back to the client, rendered in a protocol-specific way.

```js
this.on ('READ', Books, req => {
Expand All @@ -392,6 +396,7 @@ this.on ('READ', Books, req => {
})
```

The additional `options` argument can be used to specify content disposition headers in case of [custom streaming (beta)](best-practices#custom-streaming-beta).

### req. reject ({ ... }) {.method #req-reject}

Expand Down