httpclient

package
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 1, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package httpclient provides a reusable HTTP client for JSON-based APIs.

Index

Constants

View Source
const (
	// OctetStream represents the MIME type for binary data.
	OctetStream = "application/octet-stream"

	// ApplicationJSON represents the MIME type for JSON data.
	ApplicationJSON = "application/json"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type APIError

type APIError struct {
	Error struct {
		Message string `json:"message"`
		Type    string `json:"type"`
	} `json:"error"`
}

APIError represents a standard error response from the API.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client defines a reusable abstraction for JSON-based APIs.

func NewClient

func NewClient(baseURL, headerName, headerValue string) *Client

NewClient initializes a reusable HTTP client. When headerName is non-empty, every outgoing request carries authentication in the form of headerName: headerValue.

func (*Client) Do

func (c *Client) Do(ctx context.Context, method, path string, queryParams map[string]string, payload any, out any) error

Do sends a request and decodes the JSON response into the provided 'out'. Pass a pointer as 'out' (e.g. &myStruct). If out is nil, the response body is discarded.

type Field

type Field struct {
	Name  string
	Value any
}

Field represents a simple field form part

func (*Field) WriteTo

func (f *Field) WriteTo(writer *multipart.Writer) error

WriteTo writes the field to the multipart.Writer

type File

type File struct {
	Name     string
	FileName string
	Reader   io.Reader
}

File represents a file form part

func (*File) WriteTo

func (f *File) WriteTo(writer *multipart.Writer) error

WriteTo writes the file to the multipart.Writer

type FormPart

type FormPart interface {
	// Write adds the part to the multipart.Writer
	WriteTo(writer *multipart.Writer) error
}

FormPart is the common interface for all form parts

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL