Skip to content

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

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

Request and Response

ModuleDescription
Request Options28 WithXxx request option functions (headers, body, authentication, cookies, callbacks, etc.)
MiddlewareChain composition, 8 built-in middleware factories, and audit event types
Error TypesClientError, 12 ErrorType enums, and 12 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

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 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