github.com/dirkm/go-swagger@v0.19.0/examples/stream-server/README.md (about)

     1  # Purpose
     2  This directory contains a project that shows how to generate a server with `go-swagger` that can return a stream of newline-delimited JSON bodies.
     3  
     4  # How To Use This Project
     5  ## Build and Run
     6  (All following instructuctions are to be run in the directory paralle to this file.)
     7  
     8  1. Generate the code: `$ swagger generate server -f swagger.yml`
     9  2. Install the project: `$ go install ./...`
    10  3. Run the server: `$ $GOPATH/bin/countdown-server --port=8000`
    11  
    12  ## See the streaming output
    13  In another terminal window, request some streaming output:
    14  ```
    15  $ curl -v http://127.0.0.1:8000/elapse/5
    16  * About to connect() to 127.0.0.1 port 8000 (#0)
    17  *   Trying 127.0.0.1...
    18  * Adding handle: conn: 0x7fdd8400a600
    19  * Adding handle: send: 0
    20  * Adding handle: recv: 0
    21  * Curl_addHandleToPipeline: length: 1
    22  * - Conn 0 (0x7fdd8400a600) send_pipe: 1, recv_pipe: 0
    23  * Connected to 127.0.0.1 (127.0.0.1) port 8000 (#0)
    24  > GET /elapse/5 HTTP/1.1
    25  > User-Agent: curl/7.30.0
    26  > Host: 127.0.0.1:8000
    27  > Accept: */*
    28  >
    29  < HTTP/1.1 200 OK
    30  < Content-Type: application/json
    31  < Date: Sun, 11 Sep 2016 00:54:34 GMT
    32  < Transfer-Encoding: chunked
    33  <
    34  {"remains":5}
    35  {"remains":4}
    36  {"remains":3}
    37  {"remains":2}
    38  {"remains":1}
    39  {"remains":0}
    40  * Connection #0 to host 127.0.0.1 left intact
    41  $
    42  ```
    43  ## See an error condition
    44  Also in another terminal window, see an error message (not streaming):
    45  ```
    46  $ curl -v http://127.0.0.1:8000/elapse/11
    47  * About to connect() to 127.0.0.1 port 8000 (#0)
    48  *   Trying 127.0.0.1...
    49  * Adding handle: conn: 0x7f8582004000
    50  * Adding handle: send: 0
    51  * Adding handle: recv: 0
    52  * Curl_addHandleToPipeline: length: 1
    53  * - Conn 0 (0x7f8582004000) send_pipe: 1, recv_pipe: 0
    54  * Connected to 127.0.0.1 (127.0.0.1) port 8000 (#0)
    55  > GET /elapse/11 HTTP/1.1
    56  > User-Agent: curl/7.30.0
    57  > Host: 127.0.0.1:8000
    58  > Accept: */*
    59  >
    60  < HTTP/1.1 403 Forbidden
    61  < Content-Type: application/json
    62  < Date: Sun, 11 Sep 2016 00:54:48 GMT
    63  < Content-Length: 0
    64  <
    65  * Connection #0 to host 127.0.0.1 left intact
    66  $
    67  ```