You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: UPGRADING.md
+64
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,70 @@
1
1
Upgrading Grape
2
2
===============
3
3
4
+
### Upgrading to >= 1.4.0
5
+
6
+
#### Reworking stream and file and un-deprecating stream like-objects
7
+
8
+
Previously in 0.16 stream-like objects were deprecated. This release restores their functionality for use-cases other than file streaming.
9
+
10
+
This release deprecated `file` in favor of `sendfile` to better document its purpose.
11
+
12
+
To deliver a file via the Sendfile support in your web server and have the Rack::Sendfile middleware enabled. See [`Rack::Sendfile`](https://www.rubydoc.info/gems/rack/Rack/Sendfile).
13
+
```ruby
14
+
classAPI < Grape::API
15
+
get '/'do
16
+
sendfile '/path/to/file'
17
+
end
18
+
end
19
+
```
20
+
21
+
Use `stream` to stream file content in chunks.
22
+
23
+
```ruby
24
+
classAPI < Grape::API
25
+
get '/'do
26
+
stream '/path/to/file'
27
+
end
28
+
end
29
+
```
30
+
31
+
Or use `stream` to stream other kinds of content. In the following example a streamer class
32
+
streams paginated data from a database.
33
+
34
+
```ruby
35
+
classMyObject
36
+
attr_accessor:result
37
+
38
+
definitialize(query)
39
+
@result= query
40
+
end
41
+
42
+
defeach
43
+
yield'['
44
+
# Do paginated DB fetches and return each page formatted
0 commit comments