Skip to main content

πŸ“¦ apir – Simple Go HTTP API Client

The apir package provides a clean and reusable HTTP client for working with REST APIs. It supports all major HTTP methods, handles JSON encoding/decoding automatically, and simplifies file uploads and header management.

πŸ”§ Installation


πŸš€ Quick Start

You can enable debug mode using: apir.NewAPIClient(baseURL, headers, true)

πŸ“˜ Supported HTTP Methods

All request methods automatically:
  • Encode requestBody as JSON (if provided)
  • Decode the response into responseStruct
  • Return a meaningful error if status is not 2xx

GET

POST

PUT

DELETE

PATCH

OPTIONS

CONNECT

TRACE


πŸ“€ File Uploads

Use UploadFile to send files as multipart/form-data.

🧰 Header Management

Add a Header

Remove a Header


βš™οΈ Low-Level Access

sendRequest

Use if you need raw control over request sending.
Returns raw response body as []byte.

βœ… Example


πŸ“Œ Notes

  • Request body must be a Go struct or map[string]interface{}.
  • Responses are unmarshaled directly into the target struct.
  • Returns a descriptive error if the server responds with a non-2xx status code.