• This repository has been archived on 22/Nov/2021
  • Stars
    star
    5
  • Rank 2,771,004 (Top 57 %)
  • Language
    Go
  • License
    MIT License
  • Created over 2 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

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).