requist

package module
v1.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 21, 2020 License: MIT Imports: 12 Imported by: 2

README

requist

Go Quality Report GoDoc

Requist is a Go Library to manage HTTP/S Requests easily

Getting started

  • API documentation is available via godoc.
  • The examples directory contains more elaborate example applications.

Installation

To install Requist package, you need to install Go and set your Go workspace first.

1 - The first need Go installed (version 1.13+ is required). Then you can use the below Go command to install Requist

$ go get -u github.com/dotWicho/requist

And then Import it in your code:

package main

import "github.com/dotWicho/requist"

Or

2 - Use as module in you project (go.mod file):

module myclient

go 1.13

require (
	github.com/dotWicho/requist v1.2.2
)

Contributing

Documentation

Index

Constants

View Source
const (
	TextContentType string = "text/plain"
	JsonContentType string = "application/json"
	FormContentType string = "application/x-www-form-urlencoded"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BodyProvider

type BodyProvider interface {
	// ContentType returns the Content-Type of the body.
	ContentType() string
	// Body returns the io.Reader body.
	Body() (io.Reader, error)
}

BodyProvider provides Body content for http.Request attachment.

type BodyResponse

type BodyResponse interface {
	// Decode decodes the response into the value pointed to by v.
	Accept() string
	Decode(resp io.Reader, v interface{}) (err error)
}

BodyResponse decodes http responses into struct values.

type Requist

type Requist struct {
	// contains filtered or unexported fields
}

Requist struct Encapsulate an HTTP(S) requests builder and sender

func New

func New(baseURL string) *Requist

New function

@param baseURL
@return Requist class pointer

func (*Requist) Accept added in v1.0.0

func (r *Requist) Accept(accept string)

Accept sets the response's body mimeType

func (*Requist) AddHeader

func (r *Requist) AddHeader(key, value string)

AddHeader adds the key, value pair in Headers, appending values for existing keys to the key's values. Header keys are canonicalized.

func (*Requist) AddQueryParam

func (r *Requist) AddQueryParam(key, value string)

AddQueryParam adds the key, value tuples in QueryParams, appending values for existing keys

func (*Requist) Base

func (r *Requist) Base(base string) *Requist

Base sets base url to use for a client

func (*Requist) BodyAsForm

func (r *Requist) BodyAsForm(body interface{}) *Requist

BodyAsForm sets the Requests's body from a formProvider

func (*Requist) BodyAsJSON

func (r *Requist) BodyAsJSON(body interface{}) *Requist

BodyAsJSON sets the Requests's body from a jsonProvider

func (*Requist) BodyAsText added in v1.0.0

func (r *Requist) BodyAsText(body interface{}) *Requist

BodyAsText sets the Requests's body from a textProvider

func (*Requist) BodyProvider

func (r *Requist) BodyProvider(body BodyProvider) *Requist

BodyProvider sets the Requests's body provider from original BodyProvider interface{}

func (*Requist) BodyResponse added in v1.0.0

func (r *Requist) BodyResponse(body BodyResponse) *Requist

BodyResponse sets the response's body

func (*Requist) CleanQueryParams added in v0.7.0

func (r *Requist) CleanQueryParams()

CleanQueryParams remove all keys from QueryParams

func (*Requist) Connect

func (r *Requist) Connect(path string, success, failure interface{}) (*Requist, error)

Connect implement CONNECT HTTP Method

func (*Requist) DelHeader

func (r *Requist) DelHeader(key string)

DelHeader remove the key, value pair in Headers

func (*Requist) DelQueryParam

func (r *Requist) DelQueryParam(key string)

DelQueryParam remove the key from QueryParams

func (*Requist) Delete

func (r *Requist) Delete(path string, success, failure interface{}) (*Requist, error)

Delete implement DELETE HTTP Method

func (*Requist) Get

func (r *Requist) Get(path string, success, failure interface{}) (*Requist, error)

Get implement GET HTTP Method

func (*Requist) GetBasicAuth

func (r *Requist) GetBasicAuth() string

GetBasicAuth return the auth stored at the Requist class

func (*Requist) Head

func (r *Requist) Head(path string, success, failure interface{}) (*Requist, error)

Head implement HEAD HTTP Method

func (*Requist) Method

func (r *Requist) Method(method string) *Requist

Method set HTTP Method to execute

func (*Requist) New

func (r *Requist) New(baseURL string) *Requist

New class function

@param Requist class pointer, previous existing instance
@return Requist class pointer who clone some data from passed class

func (*Requist) Options

func (r *Requist) Options(path string, success, failure interface{}) (*Requist, error)

Options implement OPTIONS HTTP Method

func (*Requist) Patch

func (r *Requist) Patch(path string, success, failure interface{}) (*Requist, error)

Patch implement PATCH HTTP Method

func (*Requist) Path

func (r *Requist) Path(path string) *Requist

Path sets request path to use in next request

func (*Requist) Post

func (r *Requist) Post(path string, success, failure interface{}) (*Requist, error)

Post implement POST HTTP Method

func (*Requist) Put

func (r *Requist) Put(path string, success, failure interface{}) (*Requist, error)

Put implement PUT HTTP Method

func (*Requist) Request

func (r *Requist) Request(success, failure interface{}) (*Requist, error)

Request ... Here it's where the magic show up

func (*Requist) SetBasicAuth

func (r *Requist) SetBasicAuth(username, password string) *Requist

SetBasicAuth sets the Authorization header to use HTTP Basic Authentication

func (*Requist) SetClientTimeout added in v1.0.2

func (r *Requist) SetClientTimeout(timeout time.Duration)

SetClientTimeout take timeout param and set client Timeout seconds based

func (*Requist) SetClientTransport added in v1.1.0

func (r *Requist) SetClientTransport(transport *http.Transport)

SetClientTransport take transport param and set client HTTP Transport

func (*Requist) SetHeader

func (r *Requist) SetHeader(key, value string)

SetHeader sets the key, value pair in Headers, replacing existing values associated with key. Header keys are canonicalized.

func (*Requist) SetQueryParam

func (r *Requist) SetQueryParam(key, value string)

SetQueryParam set the key, value tuples in params to

func (*Requist) StatusCode

func (r *Requist) StatusCode() int

StatusCode return the HTTP StatusCode from last request

func (*Requist) Trace

func (r *Requist) Trace(path string, success, failure interface{}) (*Requist, error)

Trace implement TRACE HTTP Method

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL