π¦ 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.