{"modulePath":"github.com/the-dev-tools/dev-tools/packages/server","version":"v0.0.0-20261108121446-820be1ff163d","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package httpclient\n\n## Constants\n\n```go\nconst (\n\tStreamPresetOpenAI    = \"openai\"\n\tStreamPresetAnthropic = \"anthropic\"\n\tStreamPresetVercelAI  = \"vercel-ai\"\n\t// StreamPresetSSE is raw Server-Sent Events: the text is every data payload.\n\tStreamPresetSSE = \"sse\"\n)\n```\nStream presets: how a streamed response's text is assembled from its events.\n\n```go\nconst DefaultStreamTimeout = 30 * time.Second\n```\nDefaultStreamTimeout bounds how long a stream may stay open.\n\n```go\nconst MaxStreamEvents = 10000\n```\nMaxStreamEvents bounds the events kept per response; EventCount still counts all of them.\n\n```go\nconst TimeoutRequest = 60 * time.Second\n```\n\n## Variables\n\n```go\nvar StreamPresets = []string{StreamPresetOpenAI, StreamPresetAnthropic, StreamPresetVercelAI, StreamPresetSSE}\n```\nStreamPresets lists every preset.\n\n## Functions\n\n```go\nfunc ConvertHeadersToHttp(headers []Header) http.Header\n```\n\n```go\nfunc ConvertQueriesToUrl(queries []Query, url url.Values) url.Values\n```\n\n```go\nfunc Cookies(client HttpClient) map[string]string\n```\nCookies returns the latest value of every cookie the client has received, by name. Empty for a client that doesn't use a recording jar.\n\n```go\nfunc IsStreamPreset(p string) bool\n```\nIsStreamPreset reports whether p names a preset.\n\n```go\nfunc New() *http.Client\n```\n\n```go\nfunc SendRequest(client HttpClient, req *Request) (*http.Response, error)\n```\n\n```go\nfunc SendRequestWithContext(ctx context.Context, client HttpClient, req *Request) (*http.Response, error)\n```\n\n```go\nfunc WithoutRedirects(ctx context.Context) context.Context\n```\nWithoutRedirects marks a request context so a client from New returns a 30x response as is instead of following it (the yamlflow request option follow\\_redirects: false). Other requests on the same client still follow redirects.\n\n## Types\n\n```go\ntype Header struct {\n\tHeaderKey string\n\tValue     string\n}\n```\n\n```go\nfunc ConvertHttpHeaderToHeaders(headers http.Header) []Header\n```\n\n```go\ntype HttpClient interface {\n\tDo(req *http.Request) (*http.Response, error)\n}\n```\n\n```go\ntype Query struct {\n\tQueryKey string\n\tValue    string\n}\n```\n\n```go\ntype Request struct {\n\tMethod  string\n\tURL     string\n\tQueries []Query\n\tHeaders []Header\n\tBody    []byte\n}\n```\n\n```go\ntype Response struct {\n\tStatusCode int      `json:\"statusCode\"`\n\tBody       []byte   `json:\"body\"`\n\tHeaders    []Header `json:\"headers\"`\n\t// URL is the URL the response came from, after any redirects; Redirects is how many\n\t// redirects were followed to get there.\n\tURL       string `json:\"url,omitempty\"`\n\tRedirects int    `json:\"redirects,omitempty\"`\n\t// Stream is set when the response was read as a stream (see SendRequestAndConvertStream).\n\tStream *StreamResult `json:\"stream,omitempty\"`\n}\n```\n\n```go\nfunc SendRequestAndConvert(client HttpClient, req *Request, exampleID idwrap.IDWrap) (Response, error)\n```\n\n```go\nfunc SendRequestAndConvertStream(ctx context.Context, client HttpClient, req *Request, exampleID idwrap.IDWrap, opts *StreamOptions) (Response, error)\n```\nSendRequestAndConvertStream sends a request and converts the response. The body is read as a stream when opts is set or the response is text/event-stream; otherwise it is read whole, as SendRequestAndConvertWithContext does.\n\n```go\nfunc SendRequestAndConvertWithContext(ctx context.Context, client HttpClient, req *Request, exampleID idwrap.IDWrap) (Response, error)\n```\nSendRequestAndConvertWithContext sends a request and converts the response. A text/event-stream response is read as a raw SSE stream (see SendRequestAndConvertStream).\n\n```go\ntype ResponseVar struct {\n\tStatusCode int               `json:\"status\"`\n\tBody       any               `json:\"body\"`\n\tHeaders    map[string]string `json:\"headers\"`\n\tDuration   int32             `json:\"duration\"`\n\t// URL is the final URL after redirects (response.url); Redirects how many were followed\n\t// (response.redirects).\n\tURL       string `json:\"url\"`\n\tRedirects int    `json:\"redirects\"`\n\t// Stream is the streamed response's result; StreamFields exposes it to expressions.\n\tStream *StreamResult `json:\"-\"`\n}\n```\n\n```go\nfunc ConvertResponseToVar(r Response) ResponseVar\n```\n\n```go\nfunc (r ResponseVar) StreamFields() map[string]any\n```\nStreamFields are the response fields a streamed response adds: text, events, event\\_count, ttft\\_ms (when a token arrived) and usage (when the stream reported it). Nil when the response was not streamed.\n\n```go\ntype StreamEvent struct {\n\tEvent string `json:\"event,omitempty\"`\n\tData  any    `json:\"data\"`\n\tID    string `json:\"id,omitempty\"`\n}\n```\nStreamEvent is one event of a streamed response. Data is the parsed JSON when the payload is JSON, else the text.\n\n```go\ntype StreamOptions struct {\n\t// Preset assembles the text; \"\" is raw sse.\n\tPreset string\n\t// Timeout is the longest the stream may stay open; 0 is DefaultStreamTimeout.\n\tTimeout time.Duration\n}\n```\nStreamOptions asks for a response to be read as a stream.\n\n```go\ntype StreamResult struct {\n\tPreset string `json:\"preset\"`\n\t// Text is the message assembled by the preset.\n\tText string `json:\"text\"`\n\t// Events are the first MaxStreamEvents events; EventCount counts all of them.\n\tEvents     []StreamEvent `json:\"events,omitempty\"`\n\tEventCount int           `json:\"event_count\"`\n\t// TTFT is the time from sending the request to the first event that added text (raw sse:\n\t// the first data event). Nil when none did.\n\tTTFT *time.Duration `json:\"ttft,omitempty\"`\n\t// Usage is the token usage the stream reported, merged across events.\n\tUsage map[string]any `json:\"usage,omitempty\"`\n}\n```\nStreamResult is what a streamed response assembled.\n\n","path":"github.com/the-dev-tools/dev-tools/packages/server/pkg/httpclient","name":"httpclient","synopsis":"","isRedistributable":true}
