Publish a Message

    The server supports publishing SSE messages via HTTP POST to the URL path configured by the --pub-path=<path> option (defaults to /sse).

    It accepts data encoded as both application/x-www-form-urlencoded and application/json. The specific content type must always be indicated in the request or it will be rejected.

    curl \
      --include \
      --request POST \
      --header "content-type: application/json" \
      --data-raw '{"data": "Hello World"}' \
      127.0.0.1:1983/sse
    

    A successful publish will respond with a 202 Accepted status code and an application/json body with the current number of subscribers and the number of messages in the queue that have not been delivered to all subscribers (yet).

    HTTP/1.1 202 Accepted
    content-type: application/json
    content-length: 31
    
    {"queued": 1, "subscribers": 1}
    

    The size of the internal message queue can be configured with the --capacity=<size> option. It defaults to 256.

    SSE message fields

    All fields are optional but at least one must be provided or the message will be rejected with a 400 Bad Request error.

    {
      "id": "some-id",
      "event": "custom-event",
      "data": "Some data",
      "comment": ["First comment", "Second comment"]
    }
    

    Equivalent message as application/x-www-form-urlencoded:

    id=some-id
    &event=custom-event
    &data=Some%20data
    &comment=First%20comment
    &comment=Second%20comment
    

    data containing newlines is automatically split across multiple data: lines in the SSE message.