/basit

BASIT HTTP REQUEST

Primary LanguageGoMIT LicenseMIT

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)
}