Giter Club home page Giter Club logo

httpclient's Introduction

RemoteHTTP

Table of Contents

  1. Information
  2. Requirements
  3. Go doc

Information

This library is provides a simple method for interacting with remote http servers.

Requirements

This library does not have any non-standard requirements.

Usage

import "github.com/TheSp1der/httpclient"
import "log"

func main() {
     x := httpclient.DefaultClient()
     x.SetHeader("Accept", "application/json")
     x.SetHeader("Content-Type", "application/json")
     x.SetBasicAuth("username", "password")
     x.SetPostData("{}")

     output, err := x.Get("http://example.com")
     if err != nil {
          log.Println(err.Error())
     }

     log.Println(string(output))
}

Go Documentation

import "github.com/TheSp1der/httpclient"

  • type HTTPClient
  • func DefaultClient() *HTTPClient
  • func NewClient(httpClient *http.Client) *HTTPClient
  • func (c *HTTPClient) Get(url string) ([]byte, error)
  • func (c *HTTPClient) Patch(url string) ([]byte, error)
  • func (c *HTTPClient) Post(url string) ([]byte, error)
  • func (c *HTTPClient) Put(url string) ([]byte, error)
  • func (c *HTTPClient) SetBasicAuth(username, password string) *HTTPClient
  • func (c *HTTPClient) SetHeader(label string, value string) *HTTPClient
  • func (c *HTTPClient) SetPostData(data string) *HTTPClient

Package files

remotehttp.go

type HTTPClient

type HTTPClient struct {
    Client  *http.Client
    Data    *bytes.Buffer
    Headers map[string]string

    Username string
    Password string
}

HTTPClient is an interface for initializing the http client library.

func DefaultClient

func DefaultClient() *HTTPClient

DefaultClient is a function for defining a basic HTTP client with standard timeouts.

func NewClient

func NewClient(httpClient *http.Client) *HTTPClient

Create an HTTPClient with a user-provided net/http.Client

func (*HTTPClient) Get

func (c *HTTPClient) Get(url string) ([]byte, error)

Get calls the net.http GET operation

func (*HTTPClient) Patch

func (c *HTTPClient) Patch(url string) ([]byte, error)

Patch calls the net.http PATCH operation

func (*HTTPClient) Post

func (c *HTTPClient) Post(url string) ([]byte, error)

Post calls the net.http POST operation

func (*HTTPClient) Put

func (c *HTTPClient) Put(url string) ([]byte, error)

Put calls the net.http PUT operation

func (*HTTPClient) SetBasicAuth

func (c *HTTPClient) SetBasicAuth(username, password string) *HTTPClient

SetBasicAuth is a chaining function to set the username and password for basic authentication

func (*HTTPClient) SetHeader

func (c *HTTPClient) SetHeader(label string, value string) *HTTPClient

SetHeader is a chaining function to set arbitrary HTTP Headers

func (*HTTPClient) SetPostData

func (c *HTTPClient) SetPostData(data string) *HTTPClient

SetPostData is a chaining function to set POST/PUT/PATCH data

httpclient's People

Contributors

thesp1der avatar

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.