Skip to content

tinh-tinh/fetch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

40 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

HTTP Fetch for Tinh Tinh

Tinh Tinh Logo

Overview

A flexible, type-safe HTTP client for the Tinh Tinh Framework, inspired by fetch/axios, supporting full-featured requests, easy configuration, and integration with Tinh Tinh modules.

Install

go get -u github.com/tinh-tinh/fetch/v2

Features

  • Simple and chainable syntax for all HTTP verbs (GET, POST, PUT, PATCH, DELETE, etc.)
  • Base URL and per-request configuration
  • Automatic JSON encoding/decoding (customizable)
  • Query parameter and header support
  • Timeout and cancellation (context-based)
  • Cookie and credential management
  • Response formatting with type inference
  • Full integration as a Tinh Tinh module/provider

Quick Usage

Create a Fetch Instance

import "github.com/tinh-tinh/fetch/v2"

client := fetch.Create(&fetch.Config{
    BaseUrl: "https://jsonplaceholder.typicode.com",
    Headers: map[string][]string{
        "x-api-key": {"abcd", "efgh"},
    },
    Timeout: 5 * time.Second,
    ResponseType: "json",
})

Make HTTP Requests

// GET with query params
type Query struct {
    PostID int `query:"postId"`
}
res := client.Get("comments", &Query{PostID: 1})

// POST with body and query
type Post struct {
    UserID int    `json:"userId"`
    Title  string `json:"title"`
    Body   string `json:"body"`
}
res = client.Post("posts", &Post{UserID: 1, Title: "foo", Body: "bar"}, &Query{PostID: 1})

// PUT, PATCH, DELETE
client.Put("posts/1", &Post{UserID: 1, Title: "updated", Body: "new"}, &Query{PostID: 1})
client.Patch("posts/1", &Post{UserID: 1, Title: "patch", Body: "body"}, &Query{PostID: 1})
client.Delete("posts/1", &Query{PostID: 1})

Contributing

We welcome contributions! Please feel free to submit a Pull Request.

Support

If you encounter any issues or need help, you can:

  • Open an issue in the GitHub repository
  • Check our documentation
  • Join our community discussions

About

๐ŸŒ HTTP client for the Tinh Tinh Framework

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published