Response
The response can take various forms, including strings, maps, models, serializers, lists of models, and various types of exceptions.
Info
Models and lists of models will be automatically converted into JSON format and arrays of JSON.
Files and big responses
Return a File or a Stream<List<int>>. Dox pipes it to the client. It does not load it all into memory.
- A
FilesetsContent-Type(from the file name),Content-LengthandAccept-Ranges. - It answers
Range: bytes=...with206 Partial Content. Video players can seek, and downloads can resume. Storage().stream()andStorage().download()on the local disk also stream the file.
With
Headers
Status code
Content type
Stream
StreamFile file = await Storage().stream('filename.jpg');
return response().stream(file.stream).contentType(file.contentType);
Cookie
Encrypt / Decrypt
By default, a cookie's value is encrypted and decrypted using the APP_KEY. You can opt to disable encryption by setting encrypt: false when setting a cookie and disable decryption by setting decrypt: false when retrieving a cookie, eg. req.cookie(key, decrypt: false).