sse icon indicating copy to clipboard operation
sse copied to clipboard

add NewClientFromReq method to allow streaming any kind of requests

Open radiantspace opened this issue 1 year ago • 0 comments

Allows making sse clients from any kind of requests, not just GET.

I needed that for streaming responses from OpenAI like this:

req, err := http.NewRequestWithContext(ctx, http.MethodPost, "https://api.openai.com/v1/chat/completions", bytes.NewBuffer(body))
if err != nil {
    return nil, err
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer "+a.authToken)

client := sse.NewClientFromReq(req)

...

Closes https://github.com/r3labs/sse/issues/153

radiantspace avatar Jun 03 '23 16:06 radiantspace