API Reference
HTTPC provides 28 request option functions, 5 configuration presets, 8 built-in middleware, and complete download support.
Core Architecture
HTTPC uses a two-layer design: the Layer 1 method API is a thin wrapper, and 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
| Module | Description |
|---|---|
| Package Functions & Client Methods | Package-level functions like Get/Post/Put/Patch/Delete, client methods, and helper functions |
| Configuration | Config struct, 5 configuration presets, validation functions, and cookie security |
| Interfaces | Core interfaces including Client, Doer, DomainClienter, and RetryPolicy |
| Result | Result, RequestInfo, ResponseInfo, RequestMeta types and all methods |
| Handler Pipeline | Handler pipeline, MiddlewareFunc onion chain, Chain combinator, and mutator contracts |
Request and Response
| Module | Description |
|---|---|
| Request Options | 28 WithXxx request option functions (headers, body, authentication, cookies, callbacks, etc.) |
| Middleware | Chain composition, 8 built-in middleware factories, and audit event types |
| Error Types | ClientError, 12 ErrorType enums, and 12 error variables |
Advanced Features
| Module | Description |
|---|---|
| Domain Client | DomainClient creation, HTTP methods, download methods, and URL concatenation rules |
| Session Management | SessionManager cookie/header management and security validation |
| File Download | Download functions, DownloadConfig, resumable downloads, and security protection |
| Constants and Types | BodyKind enum, FormData/FileData, and audit context keys |
Quick Reference
Creating a Client
go
client, err := httpc.New() // Default configuration
client, err := httpc.New(httpc.SecureConfig()) // Secure preset
client, err := httpc.New(customConfig) // Custom configurationSending 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