2015-10-02 03:24:38 +02:00
|
|
|
---
|
|
|
|
title: Streaming Response
|
|
|
|
menu:
|
2015-10-08 22:54:31 +02:00
|
|
|
side:
|
2015-10-02 03:24:38 +02:00
|
|
|
parent: recipes
|
2015-10-08 22:54:31 +02:00
|
|
|
weight: 9
|
2015-10-02 03:24:38 +02:00
|
|
|
---
|
2015-06-30 20:51:08 +02:00
|
|
|
|
2015-06-30 21:10:35 +02:00
|
|
|
- Send data as it is produced
|
|
|
|
- Streaming JSON response with chunked transfer encoding
|
|
|
|
|
2015-10-08 02:04:51 +02:00
|
|
|
### Server
|
2015-07-03 08:21:21 +02:00
|
|
|
|
2016-03-10 09:24:45 +02:00
|
|
|
`main.go`
|
2015-06-30 20:51:08 +02:00
|
|
|
|
2016-03-10 09:24:45 +02:00
|
|
|
{{< embed "streaming-response/main.go" >}}
|
2015-06-30 20:51:08 +02:00
|
|
|
|
2015-10-08 02:04:51 +02:00
|
|
|
### Client
|
2015-07-03 08:21:21 +02:00
|
|
|
|
2015-07-03 20:50:59 +02:00
|
|
|
```sh
|
|
|
|
$ curl localhost:1323
|
|
|
|
```
|
2015-06-30 21:10:35 +02:00
|
|
|
|
2015-07-03 08:21:21 +02:00
|
|
|
## Output
|
|
|
|
|
|
|
|
```sh
|
2015-06-30 21:10:35 +02:00
|
|
|
{"Altitude":-97,"Latitude":37.819929,"Longitude":-122.478255}
|
|
|
|
{"Altitude":1899,"Latitude":39.096849,"Longitude":-120.032351}
|
|
|
|
{"Altitude":2619,"Latitude":37.865101,"Longitude":-119.538329}
|
|
|
|
{"Altitude":42,"Latitude":33.812092,"Longitude":-117.918974}
|
|
|
|
{"Altitude":15,"Latitude":37.77493,"Longitude":-122.419416}
|
|
|
|
```
|
|
|
|
|
2015-10-08 02:04:51 +02:00
|
|
|
### Maintainers
|
2015-10-08 00:41:15 +02:00
|
|
|
|
2015-10-08 22:54:31 +02:00
|
|
|
- [vishr](https://github.com/vishr)
|
2015-10-08 00:41:15 +02:00
|
|
|
|
2016-03-10 09:24:45 +02:00
|
|
|
### [Source Code]({{< source "streaming-response" >}})
|