GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - gadventures/httpclient: Thin layer around net/http for common logic when talking to REST APIs.

BranchesTags
Open more actions menu

Latest commit

 

History

21 Commits
21 Commits

Folders and files

NameName
Last commit message
Last commit date
.gitignore
.gitignore
 
 
.pre-commit-config.yaml
.pre-commit-config.yaml
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
client.go
client.go
 
 
client_option.go
client_option.go
 
 
client_test.go
client_test.go
 
 
coverage.sh
coverage.sh
 
 
dialers.go
dialers.go
 
 
go.mod
go.mod
 
 
go.sum
go.sum
 
 
logger.go
logger.go
 
 
redirect.go
redirect.go
 
 
redirect_test.go
redirect_test.go
 
 
request_option.go
request_option.go
 
 
request_option_test.go
request_option_test.go
 
 
requests.go
requests.go
 
 
requests_test.go
requests_test.go
 
 
response.go
response.go
 
 
round_tripper_test.go
round_tripper_test.go
 
 

Repository files navigation

HTTPClient

Go Report Card Go Reference

WARNING: alpha quality code; use at your own risk.

Thin layer around Go's net/http library with extensible configuration options.

It extracts the http code making requests to our REST APIs to be shared among various projects.

Features include:

  • Safety for concurrent usage
  • Transparent support for HTTP/2
  • Sharing Headers between requests
  • Custom redirect policies
  • Calling GET requests with context objects
  • Ability to set and share various timeouts without diving deep into net/http internals
  • Having a better understanding regarding idle connection pools

All of the above is supported by the standard library, however this thin layer allows us to do so without having to manage our own http.Client and http.Transport objects.

For more information on HTTP Timeouts read this.

Usage

package main

import (
	"context"
	"io"
	"net/http"
	"os"
	"time"

	h2 "github.com/gadventures/httpclient"
)

func main() {
	client, err := h2.New(
		h2.DialTimeout(3*time.Second),
		h2.IdleConnTimeout(30*time.Second),
		h2.Logger(os.Stderr),
		h2.MaxIdleConns(4),
	)

	responseHandler := func(ctx context.Context, resp *http.Response, err error) error {
		if err != nil {
			return err
		}
		_, err = io.Copy(os.Stdout, resp.Body)
		return err
	}

	err = client.Get(ctx, responseHandler, "https://somewhere.foo.bar.com/page.html")
}

About

Thin layer around net/http for common logic when talking to REST APIs.

developers.gadventures.com

Resources

Readme
BSD-2-Clause license
Activity
Custom properties

Stars

6 stars

Watchers

34 watching

Forks

0 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.