Skip to content

API Reference ​

HTTPC provides 32 request-option functions, 5 configuration presets, 7 built-in middleware, and complete download support.

Core Architecture ​

HTTPC uses a two-layer design: the Layer 1 method API is a lightweight wrapper, while requests are processed by the Layer 2 Handler pipeline.

text
HTTPC two-layer architecture
├── Layer 1  Method API (lightweight wrapper)
│     Package functions httpc.Get/Post/... + Client methods + request options → Result
│
└── Layer 2  Handler pipeline (request-processing engine)
      MiddlewareFunc(Handler) onion chain
      → assembles clientImpl.middlewareChain
      → executes (each request = assemble and run a Handler chain)

Module Navigation ​

Core ​

ModuleDescription
Package Functions & Client MethodsPackage-level functions like Get/Post/Put/Patch/Delete, client methods, and helper functions
ConfigurationConfig struct, 5 configuration presets, validation functions, and cookie security
InterfacesCore interfaces including Client, Doer, DomainClienter, and RetryPolicy
ResultResult, RequestInfo, ResponseInfo, RequestMeta types and all methods
Handler PipelineHandler pipeline, MiddlewareFunc onion chain, Chain combinator, and mutator contracts
MutatorsRead/write methods and type assertions of RequestMutator/ResponseMutator

Request and Response ​

ModuleDescription
Request Options32 WithXxx request-option functions (headers, body, authentication, cookies, callbacks, package-level routing, etc.)
Built-in MiddlewareChain composition, 7 built-in middleware factories, and audit event types
Error TypesClientError, 12 ErrorType enums, and 17 error variables

Advanced Features ​

ModuleDescription
Domain ClientDomainClient creation, HTTP methods, download methods, and URL concatenation rules
Session ManagementSessionManager cookie/header management and security validation
File DownloadDownload functions, DownloadConfig, resumable downloads, and security protection
Constants and TypesBodyKind enum, FormData/FileData, and audit context keys

API Map ​

An index grouped by symbol type, covering the main exported surface of github.com/cybergodev/httpc: types, functions, and key constants are listed individually, while enumerations (ErrorType*, BodyKind) and the Default*Config() constructors are summarized as groups. Per-symbol details live on the linked pages.

Client and Package-Level Functions ​

SymbolDescription
New / NewDefaultCreate a client (custom / default configuration)
Get / Post / Put / Patch / Delete / Head / Options / RequestPackage-level HTTP methods (share the internal default client)
DownloadUnified file-download entry (same name and signature on the package function / Client / DomainClient)
SetDefaultClient / CloseDefaultClientReplace and close the default client
CloseRoutedClientsClose every package-level routed client (created and cached by WithProxy/WithSystemProxy/WithTLSFingerprint)
NewDomain / NewDomainDefaultCreate domain clients
SetSecurityWarnOutputChange the destination of security-warning output
FormatBytes / FormatSpeedFormat byte counts / speeds

Request Options (32) ​

GroupOptions
Headers (3)WithHeader, WithHeaderMap, WithUserAgent
Authentication (2)WithBasicAuth, WithBearerToken
Body (7)WithJSON, WithXML, WithForm, WithFormData, WithFile, WithBinary, WithBody
Query parameters (2)WithQuery, WithQueryMap
Cookies (4)WithCookies, WithCookieMap, WithCookieString, WithSecureCookie
Request control (9)WithContext, WithTimeout, WithNoTimeout, WithMaxRetries, WithRetryNonIdempotent, WithFollowRedirects, WithMaxRedirects, WithAllowPrivateIPs, WithStreamBody
Package-level routing (3)WithProxy, WithSystemProxy, WithTLSFingerprint
Callbacks (2)WithOnRequest, WithOnResponse

For signatures, validation rules, and the Config defaults overridden by each option, see Request Options.

Result Family ​

CategorySymbols
TypesResult (17 nil-safe methods)
Status and protocolStatusCode, Proto, IsSuccess, IsRedirect, IsClientError, IsServerError
Body accessBody, RawBody
Parsing and savingUnmarshal, SaveToFile, String
CookiesResponseCookies, GetCookie, HasCookie, RequestCookies, GetRequestCookie, HasRequestCookie
Sub-typesRequestInfo, ResponseInfo, RequestMeta (with the ProxyURL proxy field)

See Result for details.

Configuration ​

CategorySymbols
Main typeConfig (with six groups: Timeouts / Connection / Security / Retry / Middleware / Defaults)
Sub-config typesTimeoutConfig, ConnectionConfig, SecurityConfig, RetryConfig, MiddlewareConfig, RequestDefaults
Presets (5)DefaultConfig, SecureConfig, PerformanceConfig, TestingConfig, MinimalConfig
Validation and outputValidateConfig, Config.String
Cookie securityCookieSecurityConfig, DefaultCookieSecurityConfig, StrictCookieSecurityConfig
Download configDownloadConfig, DefaultDownloadConfig, DownloadResult, DownloadProgressCallback, ChecksumAlgorithm
Session configSessionConfig, DefaultSessionConfig, NewSessionManager, NewSessionManagerDefault

See Configuration, File Download, and Session Management for details.

Handler, Middleware, and Mutators ​

CategorySymbols
Pipeline typesHandler, MiddlewareFunc, Chain
Middleware factories (7)LoggingMiddleware, RecoveryMiddleware, RequestIDMiddleware, TimeoutMiddleware, HeaderMiddleware, MetricsMiddleware, AuditMiddleware
Middleware configsLoggingConfig, RequestIDConfig, TimeoutMiddlewareConfig, HeaderConfig, MetricsConfig, AuditConfig, with their DefaultLoggingConfig, DefaultRequestIDConfig, DefaultTimeoutMiddlewareConfig, DefaultHeaderConfig, DefaultMetricsConfig, DefaultAuditConfig
MutatorsRequestMutator, ResponseMutator (the interface contract by which middleware reads and writes requests and responses), plus the split aliases RequestReader, RequestWriter, ResponseReader, ResponseWriter

See Handler Pipeline, Built-in Middleware, and Mutators for details.

Interfaces and Types ​

CategorySymbols
Core interfacesClient, Doer, DomainClienter, RetryPolicy
Option typesRequestOption (interface), RequestOptionFunc (function adapter)
Type aliasesClientError, ErrorType, CertificatePinner, ProxyStrategy
Certificate pinningNewSPKIHashPinner, NewPublicKeyPinner, NewCertificatePinnerChain
Session and domainSessionManager, DomainClient (recommended for use through the DomainClienter interface)
Data typesFormData, FileData, AuditEvent

See Interfaces, Domain Client, Session Management, and Constants and Types for details.

Errors and Constants ​

CategorySymbols
Error typesClientError, ErrorType (12 categories: ErrorTypeUnknown, ErrorTypeNetwork, ErrorTypeTimeout, ErrorTypeContextCanceled, ErrorTypeResponseRead, ErrorTypeTransport, ErrorTypeRetryExhausted, ErrorTypeTLS, ErrorTypeCertificate, ErrorTypeDNS, ErrorTypeValidation, ErrorTypeHTTP)
Sentinel errors (17)ErrClientClosed, ErrNilConfig, ErrInvalidHeader, ErrInvalidTimeout, ErrInvalidRetry, ErrInvalidMaxRedirects, ErrInvalidCredentials, ErrInvalidConnection, ErrInvalidSecurity, ErrInvalidMiddleware, ErrEmptyFilePath, ErrFileExists, ErrResponseBodyEmpty, ErrResponseBodyTooLarge, ErrStreamBodyRequiresDownload, ErrDownloadInProgress, ErrProxyConnectionFailed
BodyKind (6 constants)BodyAuto, BodyJSON, BodyXML, BodyForm, BodyBinary, BodyMultipart
Other constantsProxyStrategyRoundRobin / ProxyStrategyRandom, ChecksumSHA256, audit context keys SourceIPKey / UserIDKey

See Error Types and Constants and Types for details.

Quick Reference ​

Creating a Client ​

go
client, err := httpc.NewDefault()             // Default configuration
client, err := httpc.New(httpc.SecureConfig()) // Secure preset
client, err := httpc.New(customConfig)         // Custom configuration

Sending Requests ​

go
// Package-level functions
result, err := httpc.Get(url, options...)

// Client methods
result, err := client.Get(url, options...)

// With context
result, err := client.Request(ctx, "GET", url, options...)

Handling Responses ​

go
result.StatusCode()           // Status code
result.Body()                 // Response body (string)
result.RawBody()              // Response body (bytes)
result.Unmarshal(&data)       // JSON parsing
result.IsSuccess()            // Is 2xx
result.Meta.Duration          // Request duration
result.Meta.Attempts          // Total attempts (including the first)

Version Compatibility ​

  • Go version: requires Go 1.27 or later (go.mod declares go 1.27).
  • Import path: github.com/cybergodev/httpc (package name httpc, no alias needed).
  • Direct dependencies: 7 direct modules, all compiled unconditionally (there are no feature-culling build tags; platform differences are handled by GOOS-based file selection, e.g. internal/engine/errors_unix.go). golang.org/x/net and golang.org/x/sys serve the standard path; brotli / compress / uTLS / tls-client / fhttp serve the transport-fingerprint path — importing the package puts them in the build graph, and they stay idle at runtime unless Security.TLSFingerprint is enabled.
  • API status: no exported symbol currently carries a Deprecated marker; the library is under active maintenance.