📦 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
requestBodyas JSON (if provided) - Decode the response into
responseStruct - Return a meaningful error if status is not 2xx
GET
POST
PUT
DELETE
PATCH
OPTIONS
HEAD
CONNECT
TRACE
📤 File Uploads
UseUploadFile 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.
[]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.