http

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2024 License: LGPL-3.0 Imports: 8 Imported by: 0

README

http

A small simplification of the standard library net/http in Go.

Usage

Use go get to download the dependency.

go get github.com/Laky-64/http@latest

Then, import it in your Go files:

import "github.com/Laky-64/http"

The library is designed to be simple and easy to use. Here's an example of a simple request:

Simple Request
res, err := http.ExecuteRequest(
    "https://httpbin.org/get",
)
if err != nil {
    panic(err)
}
fmt.Println(res)
Example of a simple request
Proxy Request
res, err := http.ExecuteRequest(
    "https://ipinfo.io",
    http.Proxy("socks5://127.0.0.1:9050"),
)
if err != nil {
    panic(err)
}
fmt.Println(res)
Example of a proxy request
POST Request
res, err := http.ExecuteRequest(
    "https://httpbin.org/post",
    http.Method("POST"),
    http.Body([]byte("Hello, World!")),
)
if err != nil {
    panic(err)
}
fmt.Println(res)
Example of a post request
MultiPart Request
res, err := http.ExecuteRequest(
   "https://httpbin.org/post", 
   http.Method("POST"), 
   http.MultiPartForm(
       map[string]string{
           "key": "value",
       }, 
       map[string]types.FileDescriptor{
           "file": {
               FileName: "file.txt", 
               Content:  []byte("Hello, World!"),
           },
       },
   ),
)
if err != nil {
   panic(err)
}
fmt.Println(res)
Example of a multipart request

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExecuteRequest

func ExecuteRequest(uri string, options ...RequestOption) (*types.HTTPResult, error)

Types

type RequestOption

type RequestOption interface {
	Apply(o *types.RequestOptions)
}

func BearerToken

func BearerToken(method string) RequestOption

func Body

func Body(body []byte) RequestOption

func Cookies

func Cookies(cookies map[string]string) RequestOption

func Headers

func Headers(headers map[string]string) RequestOption

func Method

func Method(method string) RequestOption

func MultiPartForm

func MultiPartForm(data map[string]string, files map[string]types.FileDescriptor) RequestOption

func OverloadReader

func OverloadReader(reader overloadReader) RequestOption

func Proxy added in v1.0.2

func Proxy(url string) RequestOption

func Retries

func Retries(count int) RequestOption

func Timeout

func Timeout(time time.Duration) RequestOption

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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