Coder Social home page Coder Social logo

gadventures / httpclient Goto Github PK

View Code? Open in Web Editor NEW
6.0 37.0 0.0 50 KB

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

Home Page: https://developers.gadventures.com

License: BSD 2-Clause "Simplified" License

Go 98.27% Shell 1.73%

httpclient's Introduction

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")
}

httpclient's People

Contributors

jlabath avatar marz619 avatar rafikdraoui avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

httpclient's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.