Skip to content

Latest commit

 

History

History
141 lines (96 loc) · 3.04 KB

README.md

File metadata and controls

141 lines (96 loc) · 3.04 KB

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