gaxios

package module
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2023 License: MIT Imports: 7 Imported by: 0

README

A http client in Golang inspired from nodejs axios

Installation

go get github.com/mofiqul/gaxios

Read the Documentation

Example

type ResponseData struct {
	Message string `json:"message"`
}

res, err := gaxios.Get(fmt.Sprintf("%s/test", server.URL), &gaxios.GAxiosConfig{
	Header: http.Header{
		"Accept": []string{"application/json"},
	},
}) 
defer res.Data.Close()
if err != nil {
	// Handle error
}

resp := &ResponseData{}
_ = json.NewDecoder(res.Data).Decode(resp)

Or create a instance with configuation

var axios = gaxios.New( 
	&gaxios.GAxiosConfig{
		Header: http.Header{
			"Accept": []string{"application/json"},
		},
	})

res, err := axios.Get(fmt.Sprintf("%s/test", server.URL))
defer res.Data.Close()
if err != nil {
	// Handle error
}

resp := &ResponseData{}
_ = json.NewDecoder(res.Data).Decode(resp)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Delete added in v0.1.3

func Delete(url string, cfg *GAxiosConfig) (*http.Response, error)

Delete issues a DELETE to the specified URL. Caller should close resp.Data when done reading from it.

func Get added in v0.1.3

func Get(url string, cfg *GAxiosConfig) (resp *http.Response, err error)

Get issues a GET to the specified URL. Caller should close resp.Data when done reading from it.

func Patch added in v0.1.3

func Patch(
	url string,
	payload interface{},
	cfg *GAxiosConfig,
) (*http.Response, error)

Patch issues a PATCH to the specified URL. Caller should close resp.Data when done reading from it.

func Post added in v0.1.3

func Post(
	url string,
	payload interface{},
	cfg *GAxiosConfig,
) (*http.Response, error)

Post issues a POST to the specified URL. Caller should close resp.Data when done reading from it.

Types

type GAxios

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

func New

func New(cfg *GAxiosConfig) *GAxios

func (*GAxios) Delete

func (h *GAxios) Delete(url string) (*http.Response, error)

Delete issues a DELETE to the specified URL. Caller should close resp.Data when done reading from it.

func (*GAxios) Get

func (h *GAxios) Get(url string) (resp *http.Response, err error)

Get issues a GET to the specified URL. Caller should close resp.Data when done reading from it.

func (*GAxios) Patch

func (h *GAxios) Patch(url string, payload interface{}) (*http.Response, error)

Patch issues a PATCH to the specified URL. Caller should close resp.Data when done reading from it.

func (*GAxios) Post

func (h *GAxios) Post(url string, payload interface{}) (*http.Response, error)

Post issues a POST to the specified URL. Caller should close resp.Data when done reading from it.

type GAxiosConfig

type GAxiosConfig struct {
	Header    http.Header
	BaseUrl   string
	Query     map[string]string
	Timeout   time.Duration
	Transport http.RoundTripper
}

type GAxiosError added in v0.1.5

type GAxiosError struct {
	Status     int
	Header     http.Header
	StatusText string
	Request    *http.Request
	Mesaage    string
}

func (*GAxiosError) Error added in v0.1.5

func (e *GAxiosError) Error() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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