2016-10-20 20:30:53 +02:00
|
|
|
+++
|
2016-11-17 08:46:00 +02:00
|
|
|
title = "Streaming Response Example"
|
|
|
|
description = "Streaming response example for Echo"
|
2016-11-21 00:16:22 +02:00
|
|
|
[menu.main]
|
2016-10-20 20:30:53 +02:00
|
|
|
name = "Streaming Response"
|
|
|
|
parent = "recipes"
|
|
|
|
weight = 3
|
|
|
|
+++
|
|
|
|
|
|
|
|
- Send data as it is produced
|
|
|
|
- Streaming JSON response with chunked transfer encoding
|
|
|
|
|
2016-11-17 08:46:00 +02:00
|
|
|
## Server
|
2016-10-20 20:30:53 +02:00
|
|
|
|
|
|
|
`server.go`
|
|
|
|
|
|
|
|
{{< embed "streaming-response/server.go" >}}
|
|
|
|
|
2016-11-17 08:46:00 +02:00
|
|
|
## Client
|
2016-10-20 20:30:53 +02:00
|
|
|
|
|
|
|
```sh
|
|
|
|
$ curl localhost:1323
|
|
|
|
```
|
|
|
|
|
2016-11-17 08:46:00 +02:00
|
|
|
## Output
|
2016-10-20 20:30:53 +02:00
|
|
|
|
|
|
|
```sh
|
|
|
|
{"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}
|
|
|
|
```
|
|
|
|
|
2016-11-17 09:05:37 +02:00
|
|
|
## [Source Code]({{< source "streaming-response" >}})
|
|
|
|
|
2016-11-17 08:46:00 +02:00
|
|
|
## Maintainers
|
2016-10-20 20:30:53 +02:00
|
|
|
|
|
|
|
- [vishr](https://github.com/vishr)
|