requestfy

A library to facilitate the creation of http requests

Installation

Use go get command to retrieve the package (Go ^1.19 is required):

go get -u github.com/RafaelYon/requestfy

Quick Start

  1. Import it in your code:
import "github.com/RafaelYon/requestfy"
  1. Set up a HTTP Client:

client := requestfy.NewClient(
    requestfy.ConfigDefault(),
    requestfy.ConfigBaseURL("https://swapi.dev/api/")
)
  1. Make a request:
res, err := client.Request().Get("people/1/")

Configuration

Replacing JSON decoder

When starting the client with the default configuration (requestfy.ConfigDefault()) json.Decoder is used.

To replace json.Decoder with another implementation it is necessary to specify the decoder constructor during the creation of the client with the option ConfigJsonDecoder.

Using go-json

To use go-json just “teach” the client how to build the new decoder:

import "github.com/goccy/go-json"

func main() {
    client := client := requestfy.NewClient(
        requestfy.ConfigDefault(), // Using "ConfigDefault" is optional and its settings may be overwritten by subsequent settings
        requestfy.ConfigJsonDecoder(func(r io.Reader) requestfy.Decoder {
            return json.NewDecoder(r)
        })
    )
}

GitHub

View Github