Skip to content

ptthx is wrapper package for std http for the unindustrious

Notifications You must be signed in to change notification settings

AnimeshRy/ptthx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ptthx

HTTP client wrapper of std HTTP package for the unindustrious

examples

simple get request

package main

import (
	"context"
	"fmt"

	"github.com/AnimeshRy/ptthx"
)

func main() {
	cli := ptthx.New("test")

	var result map[string]interface{}

	// by default used application/json content type and json encoder/decoder

	err := cli.Get(context.Background(), "http://httpbin.org/get", &result)
	if err := nil {
		panic(err)
	}

	fmt.Println(result)
}

simple post form

package main

import (
	"context"
	"fmt"
	"net/url"

	"github.com/AnimeshRy/ptthx"
)

func main() {
	cli := ptthx.New("test")

	data := make(url.Values)
	data.Set("test", "1")
	data.Set("test2", "2")

	var result map[string]interface{}

	err := cli.Post(context.Background(), "https://httpbin.org/post", data, &result,
		ptthx.WithEncoder(httpcli.FormURLEncodedEncoder),
		ptthx.SetHeaders("content-type", "application/x-www-form-urlencoded"))
	if err != nil {
		panic(err)
	}

	fmt.Println(result)
}

or

package main

import (
	"context"
	"fmt"
	"net/url"

	"github.com/AnimeshRy/ptthx"
)

func main() {
	cli := httpcli.New("test",
		ptthx.WithEncoder(ptthx.FormURLEncodedEncoder),
		ptthx.SetHeaders("content-type", "application/x-www-form-urlencoded"),
	)

	data := make(url.Values)
	data.Set("test", "1")
	data.Set("test2", "2")

	var result map[string]interface{}

	err := cli.Post(context.Background(), "https://httpbin.org/post", data, &result)
	if err != nil {
		panic(err)
	}

	fmt.Println(result)
}

About

ptthx is wrapper package for std http for the unindustrious

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages