easy-http

module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2025 License: Apache-2.0

README

easy-http

Simple Go utilities and examples for HTTP interactions.

Features

• Go functions to simplify requests, responses, and testing.
• Coverage reporting supported via Makefile targets.
• Uses standard libraries and helpful third-party packages (e.g., YAML, testify).

Getting Started

  1. Clone or download this repo.
  2. Run "make deps" to install dependencies.
  3. Build with "make build" or test with "make tests".

Usage

Installation
go get github.com/bdpiprava/easy-http
Examples
import (
    "fmt"
    "net/http"
    "time"

    "github.com/bdpiprava/easy-http/pkg/httpx"
)

func Example() {
    // Create a client with custom base URL and timeout
    client := httpx.NewClient(
        httpx.WithDefaultBaseURL("https://api.example.com"),
        httpx.WithDefaultTimeout(5 * time.Second),
    )

    // Build a request with a specified path and query parameters
    req := httpx.NewRequest(http.MethodGet,
        httpx.WithPath("v1/users"),
        httpx.WithQueryParam("active", "true"),
    )

    // Execute the request and handle the response
    resp, err := client.Execute(*req, map[string]any{})
    if err != nil {
        // handle error
    }
    fmt.Printf("Status Code: %d\n", resp.StatusCode)
    fmt.Printf("Response Body: %+v\n", resp.Body)
}

import (
    "fmt"
    "net/http"
    "time"

    "github.com/bdpiprava/easy-http/pkg/httpx"
)

// Perform a GET request with a specified type parameter
func ExampleGET() {
    resp, err := httpx.GET[map[string]any](
        httpx.WithBaseURL("https://api.example.com"),
        httpx.WithPath("v1/posts"),
    )
    if err != nil {
        // handle error
    }
    fmt.Println(resp.Body)
}

// Perform a POST request with a specified type parameter
func ExamplePOST() {
    resp, err := httpx.POST[map[string]any](
        httpx.WithBaseURL("https://api.example.com"),
        httpx.WithPath("v1/posts"),
        httpx.WithHeader("Content-Type", "application/json"),
    )
    if err != nil {
        // handle error
    }
    fmt.Println(resp.Body)
}

Contributing

Open issues or pull requests for improvements or bug fixes.

License

Directories

Path Synopsis
examples
advanced command
basic command
circuit_breaker command
middleware command
retry command
testing command
pkg

Jump to

Keyboard shortcuts

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