Skip to content

Commit

Permalink
Updated README.md to include example usage of StreamResponse
Browse files Browse the repository at this point in the history
  • Loading branch information
Foxy-Loxy committed Mar 8, 2023
1 parent 310d7be commit 90a0c2c
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ On the BaseHttpController, we provide a litany of helper methods to ease returni
* InternalServerError
* NotFoundResult
* JsonResult
* StreamResult
```ts
import { injectable, inject } from "inversify";
Expand Down Expand Up @@ -378,6 +379,33 @@ describe("ExampleController", () => {
```
*This example uses [Mocha](https://mochajs.org) and [Chai](http://www.chaijs.com) as a unit testing framework*
### StreamResult
In some cases, you'll want to proxy data stream from remote resource in response.
This can be done by using the `stream` helper method provided by `BaseHttpController`.
Useful in cases when you need to return large data.
```ts
import { inject } from "inversify";
import {
controller, httpGet, BaseHttpController
} from "inversify-express-utils";
import TYPES from "../constants";
import { FileServiceInterface } from "../interfaces";

@controller("/cats")
export class CatController extends BaseHttpController {
@inject(TYPES.FileService) private fileService: FileServiceInterface;

@httpGet("/image")
public async getCatImage() {
const readableStream = this.fileService.getFileStream("cat.jpeg");

return this.stream(content, "image/jpeg", 200);
}
}
```
## HttpContext
The `HttpContext` property allow us to access the current request,
Expand Down

0 comments on commit 90a0c2c

Please sign in to comment.