Skip to content
This repository has been archived by the owner on Nov 22, 2021. It is now read-only.
/ httpc Public archive

A customizable and simple HTTP client library. Only depend on the stdlib HTTP client.

License

Notifications You must be signed in to change notification settings

valord577/httpc

Repository files navigation

Httpc

Mentioned in Awesome Go Go Report Card Go Reference GitHub

A customizable and simple HTTP client library. Only depend on the stdlib HTTP client.

Requirements

  • Go 1.14 or higher.

Features

  • Simple and easy to use
  • Make HTTP calls customizable

Installing

go mod:

go get github.com/valord577/httpc

Example

- Do HTTP calls
package main

import (
    "fmt"
    "net/http"
    
    "github.com/valord577/httpc"
)

func main() {
    c := httpc.PackedReq{
        URL:              "https://www.google.com",
        Method:           http.MethodGet,
        ReqBodyPublisher: httpc.PublisherNoBody{},
        RespBodyHandler:  httpc.RespBodyAsByteArray{},
    }

    bs, err := c.Send()
    if err != nil {
        panic(err)
    }
    fmt.Printf("%s", bs)
}
- Customize the processing of response body
package main

import (
    "fmt"
    "io"
    "net/http"
    
    "github.com/valord577/httpc"
)

type RespBodyAsString struct {}

func (r RespBodyAsString) Apply(body io.ReadCloser) (interface{}, error) {
    bs, err := io.ReadAll(body)
    if err != nil {
        return nil, err
    }
    return string(bs), nil
}

func main() {
    c := httpc.PackedReq{
        URL:              "https://www.google.com",
        Method:           http.MethodGet,
        ReqBodyPublisher: httpc.PublisherNoBody{},
        RespBodyHandler:  RespBodyAsString{},
    }

    bs, err := c.Send()
    if err != nil {
        panic(err)
    }
    fmt.Printf("%s", bs)
}

Changes

See the CHANGES for changes.

License

See the LICENSE for Rights and Limitations (MIT).

About

A customizable and simple HTTP client library. Only depend on the stdlib HTTP client.

Topics

Resources

License

Stars

Watchers

Forks

Languages