Documentation
¶
Index ¶
Constants ¶
const ( // RequestJSON indicates that the request body should be encoded as JSON. RequestJSON requestType = "json" // RequestForm indicates that the request body should be form-urlencoded. RequestForm requestType = "form" // RequestMultipart indicates that the request body should be multipart/form-data. RequestMultipart requestType = "multipart" // RequestRaw indicates that the request body should be passed as-is. RequestRaw requestType = "raw" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶ added in v0.0.3
type Client struct {
BaseURL string // Base URL for all requests, e.g., "https://api.example.com"
TimeoutMS int // Request timeout in milliseconds.
RequestType requestType // Default request type (e.g., RequestJSON, RequestRaw).
// contains filtered or unexported fields
}
Client is a configurable HTTP client that works across WASM and standard Go. To create a client, initialize the struct directly, for example: client := &fetchgo.Client{ BaseURL: "https://api.example.com", RequestType: fetchgo.RequestJSON }
func (*Client) AddHeader ¶ added in v0.0.3
AddHeader adds a header to the client's default headers. It will add the (key, value) pair even if the key already exists, potentially creating duplicate header keys.
func (*Client) SendRequest ¶ added in v0.0.3
SendRequest sends an HTTP request and invokes the callback with the result. It delegates the actual request logic to the environment-specific doRequest method. The entire operation, including the callback, runs in a new goroutine.
type Encoder ¶ added in v0.0.3
Encoder defines the interface for encoding and decoding data. This allows for pluggable serialization strategies (e.g., JSON, form, raw).
type JSONEncoder ¶ added in v0.0.3
type JSONEncoder struct{}
JSONEncoder implements the Encoder interface for JSON data.
type RawEncoder ¶ added in v0.0.3
type RawEncoder struct{}
RawEncoder implements the Encoder interface for raw byte data. It acts as a pass-through for []byte and converts string to []byte.