client

package
v1.9.9 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2022 License: GPL-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoRequest  = "no request has been set"                  // Error message for when no request has been set
	ErrNoCallback = "no callback has been set"                 // Error message for when no callback has been set
	ErrNoEncoding = "no encoding has been set or is not valid" // Error message for when no encoding has been set
)

Define standard error messages

Functions

This section is empty.

Types

type APIClient

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

APIClient is a client that can be used to execute http requests. - Can be used to execute GET, POST, PUT, DELETE, PATCH requests.

func NewAPIClient

func NewAPIClient() *APIClient

APIClient is a client that can be used to make requests to a server.

func (*APIClient) ChangeRequest

func (c *APIClient) ChangeRequest(cb func(rq *http.Request)) *APIClient

Change the request before it is made This is useful for adding headers, cookies, etc.

func (*APIClient) Delete

func (c *APIClient) Delete(url string) *APIClient

Initialize a DELETE request

func (*APIClient) Do

func (c *APIClient) Do(cb func(resp *http.Response))

Execute the request -> APIClient.exec

func (*APIClient) DoDecodeTo

func (c *APIClient) DoDecodeTo(decodeTo interface{}, encoding Encoding, cb func(resp *http.Response, strct interface{}))

Make a request and return the response body decoded into the specified parameter. -> APIClient.Do -> APIClient.exec

func (*APIClient) Get

func (c *APIClient) Get(url string) *APIClient

Initialize a GET request

func (*APIClient) NoRecover

func (c *APIClient) NoRecover() *APIClient

Do not reccover when an error occurs

func (*APIClient) OnError

func (c *APIClient) OnError(cb func(err error) bool) *APIClient

Set the callback function for when an error occurs

func (*APIClient) Patch

func (c *APIClient) Patch(url string) *APIClient

Initialize a PATCH request

func (*APIClient) Post

func (c *APIClient) Post(url string) *APIClient

Initialize a POST request

func (*APIClient) Put

func (c *APIClient) Put(url string) *APIClient

Initialize a PUT request

func (*APIClient) WithCookie

func (c *APIClient) WithCookie(cookie *http.Cookie) *APIClient

Add a HTTP.Cookie to the request

func (*APIClient) WithData

func (c *APIClient) WithData(formData map[string]string, encoding Encoding, file ...File) *APIClient

Add form data to the request

func (*APIClient) WithHeaders

func (c *APIClient) WithHeaders(headers map[string]string) *APIClient

Add headers to the request

func (*APIClient) WithQuery

func (c *APIClient) WithQuery(query map[string]string) *APIClient

Make a request with url query parameters

type Encoding

type Encoding string
const (
	FORM_URL_ENCODED Encoding = "application/x-www-form-urlencoded" // FORM_URL_ENCODED encoding
	MULTIPART_FORM   Encoding = "multipart/form-data"               // MULTIPART_FORM encoding
	JSON             Encoding = "json"                              // JSON encoding
	XML              Encoding = "xml"                               // XML encoding
)

Define methods of encoding

type File

type File struct {
	FileName  string    // Name of the file
	FieldName string    // Name of the field
	Reader    io.Reader // Reader of the file
}

Define a type for multipart files

type Methods

type Methods string

Define methods and encodings type

const (
	GET     Methods = "GET"     // GET method
	POST    Methods = "POST"    // POST method
	PUT     Methods = "PUT"     // PUT method
	PATCH   Methods = "PATCH"   // PATCH method
	DELETE  Methods = "DELETE"  // DELETE method
	OPTIONS Methods = "OPTIONS" // OPTIONS method
	HEAD    Methods = "HEAD"    // HEAD method
	TRACE   Methods = "TRACE"   // TRACE method

)

Define request methods

Jump to

Keyboard shortcuts

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