Skip to content

API Reference ​

HTTPC provides 29 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 thin wrapper, while the real request-processing engine is the Layer 2 Handler pipeline.

text
HTTPC two-layer architecture
├── Layer 1  Method API (thin 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 Options29 WithXxx request-option functions (headers, body, authentication, cookies, callbacks, 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 ​

A complete index grouped by symbol type, mapping one-to-one to the exported surface of the github.com/cybergodev/httpc package — click any entry to jump to its detail page.

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
NewDomain / NewDomainDefaultDomain-scoped clients
SetSecurityWarnOutputRedirect security-warning output
FormatBytes / FormatSpeedFormat byte counts / speeds

Request Options (29) ​

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
Callbacks (2)WithOnRequest, WithOnResponse

For the signatures, validation rules, and Config defaults overridden by all options, 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 (Timeouts / Connection / Security / Retry / Middleware / Defaults — six groups)
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 (each with a Default*Config() constructor)
MutatorsRequestMutator, ResponseMutator (the contract through which middleware reads/writes requests and responses)

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

Interfaces and Types ​

CategorySymbols
Core interfacesClient, Doer, DomainClienter, RetryPolicy
Type aliasesRequestOption, ClientError, ErrorType, CertificatePinner, ProxyStrategy
Certificate pinningNewSPKIHashPinner, NewPublicKeyPinner, NewCertificatePinnerChain
Session and domainSessionManager, DomainClient (recommended for use via 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 (enum of 12 error categories)
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

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          // Retry count

Version Compatibility ​

  • Go version: requires Go 1.26 or later (go.mod declares go 1.26.0).
  • Import path: github.com/cybergodev/httpc (package name httpc, no alias needed).
  • Direct dependencies: only golang.org/x/sys (for per-platform system-proxy detection, covering Linux/macOS/Windows); no other third-party dependencies.
  • API status: no exported symbol currently carries a Deprecated marker; the library is under active maintenance.