requist

package module
v1.2.7 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2021 License: MIT Imports: 13 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 latest
)

Contributing

Documentation

Index

Constants

View Source
const (

	// TextContentType is an alias to HTTP text/plain MIME Type
	TextContentType string = "text/plain"
	// JSONContentType is an alias to HTTP application/json MIME Type
	JSONContentType string = "application/json"
	// FormContentType is an alias to HTTP application/x-www-form-urlencoded MIME Type
	FormContentType string = "application/x-www-form-urlencoded"
)

Variables

Logger is the default logs handler

Functions

func IsValidBase added in v1.2.3

func IsValidBase(base string) bool

IsValidBase check validity of a base URL

func IsValidHostname added in v1.2.3

func IsValidHostname(host string) bool

IsValidHostname check validity of a hostname

func IsValidScheme added in v1.2.3

func IsValidScheme(scheme string) bool

IsValidScheme check validity of a scheme

func ParseBaseURL added in v1.2.3

func ParseBaseURL(base string) string

ParseBaseURL check if is valid the base string passed

func ParsePathURL added in v1.2.3

func ParsePathURL(base string, path string) string

ParsePathURL check relative path

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 Operations added in v1.2.6

type Operations interface {
	SetClientTransport(transport *http.Transport)
	SetClientTimeout(timeout time.Duration)
	SetClientContext(context context.Context)

	BodyProvider(body BodyProvider) *Requist
	BodyAsForm(body interface{}) *Requist
	BodyAsJSON(body interface{}) *Requist
	BodyAsText(body interface{}) *Requist
	BodyResponse(body BodyResponse) *Requist
	Accept(accept string)

	PrepareRequestURI() (string, error)

	AddHeader(key, value string)
	SetHeader(key, value string)
	DelHeader(key string)
	AddQueryParam(key, value string)
	SetQueryParam(key, value string)
	DelQueryParam(key string)
	CleanQueryParams()
	SetBasicAuth(username, password string) *Requist
	StatusCode() int
	GetBasicAuth() string

	Base(base string) *Requist
	Path(path string) *Requist
	URI(uri string) *Requist
	Method(method string) *Requist

	Get(path string, success, failure interface{}) (*Requist, error)
	Put(path string, success, failure interface{}) (*Requist, error)
	Post(path string, success, failure interface{}) (*Requist, error)
	Patch(path string, success, failure interface{}) (*Requist, error)
	Delete(path string, success, failure interface{}) (*Requist, error)
	Options(path string, success, failure interface{}) (*Requist, error)
	Connect(path string, success, failure interface{}) (*Requist, error)
}

Operations interface Define all Methods

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 Request's body from a formProvider

func (*Requist) BodyAsJSON

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

BodyAsJSON sets the Request's body from a jsonProvider

func (*Requist) BodyAsText added in v1.0.0

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

BodyAsText sets the Request's body from a textProvider

func (*Requist) BodyProvider

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

BodyProvider sets the Request'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) Method

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

Method set HTTP Method to execute

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) PrepareRequestURI added in v1.2.3

func (r *Requist) PrepareRequestURI() (uri string, err error)

PrepareRequestURI returns actual uri

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) SetClientContext added in v1.2.6

func (r *Requist) SetClientContext(context context.Context)

SetClientContext take transport param and set client HTTP Transport

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) URI added in v1.2.7

func (r *Requist) URI(uri string) *Requist

URI sets request uri to use in next request

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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