basit

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2021 License: MIT Imports: 6 Imported by: 0

README

Basit Http Request

GoDoc License Release

HTTP Client for golang, Inspired by Javascript-axios. thanks to Request for being an inspiration. a small part of the code changes from Request

Features

  • Transform request and response data

Installing

go mod:

go get github.com/ibnusurkati/basit

Methods

  • OPTIONS
  • GET
  • HEAD
  • POST
  • PUT
  • DELETE
  • TRACE
  • CONNECT

Example

package main

import (
	"fmt"

	"github.com/ibnusurkati/basit"
)

type Coba struct {
	Origin string `json:"origin"`
	Url    string `json:"url"`
}

func main() {
	var result interface{}
	client := basit.Instance{
		Url:    "http://httpbin.org/post",
		Method: "POST",
		Data: Coba{
			Origin: "bismillah",
			Url:    "Alhamdulillah",
		},
		Headers: map[string]string{
			"public-key": "hello cuy",
			"User-Agent": "irx",
		},
		DataType:     "json",
		ResponseType: "json",
	}

	resp := client.Exec(&result)
	if !resp.OK() {
		fmt.Println(resp.Error())
	}
	fmt.Println(result)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BasicAuth

type BasicAuth struct {
	Username string
	Password string
}

type Instance

type Instance struct {
	Url          string
	Method       string
	ResponseType string
	Query        map[string]string
	Headers      map[string]string
	Data         interface{}
	DataType     string
	Timeout      time.Duration
	TLSTimeout   time.Duration
	DialTimeout  time.Duration
	TLSConfig    *tls.Config
	Transport    *http.Transport
	ProxyURL     string
	ProxyServers map[string]string
	Cookies      []*http.Cookie
	CookiesMap   map[string]string
	BasicAuth    BasicAuth
}

func (*Instance) Exec

func (i *Instance) Exec(data *interface{}) *response.Response

func (*Instance) ExecDo

func (i *Instance) ExecDo() response.Response

func (*Instance) InitContext

func (i *Instance) InitContext() *context.Context

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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