MyGit
🚩收到GitHub仓库的更新通知

monaco-io/request

Fork: 30 Star: 285 (更新于 2024-05-15 23:18:12)

license: MIT

Language: Go .

go request, go http client

最后发布版本: v1.0.16 ( 2023-07-02 21:37:42)

官方网址 GitHub网址

✨免费申请网站SSL证书,支持多域名和泛域名,点击查看

Request Mentioned in Awesome Go Go Report Card Go

GoDoc codecov Release TODOs License

HTTP Client for golang, Inspired by Javascript-axios Python-request. If you have experience about axios or requests, you will love it. No 3rd dependency.

Features

  • Make http requests from Golang
  • Transform request and response data

Installing

go mod:

go get github.com/monaco-io/request

Methods

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

Example

POST

package main

import (
    "github.com/monaco-io/request"
)

func main() {
    var body = struct {
         A string
         B int
        }{A: "A", B: 1}
    var result interface{}

    c := request.Client{
        URL:    "https://google.com",
        Method: "POST",
        Query: map[string]string{"hello": "world"},
        JSON:   body,
    }
    resp := c.Send().Scan(&result)
    if !resp.OK(){
        // handle error
        log.Println(resp.Error())
    }

    // str := resp.String()
    // bytes := resp.Bytes()

POST with local files

package main

import (
    "github.com/monaco-io/request"
)

func main() {
    c := request.Client{
        URL:    "https://google.com",
        Method: "POST",
        Query: map[string]string{"hello": "world"},
        MultipartForm: MultipartForm{
            Fields: map[string]string{"a": "1"},
			Files:  []string{"doc.txt"},
        },
    }
    resp := c.Send().Scan(&result)
    ...

POST step by step

package main

import (
    "github.com/monaco-io/request"
)

func main() {
    var response interface{}

    resp := request.
        New().
        POST("http://httpbin.org/post").
        AddHeader(map[string]string{"Google": "google"}).
        AddBasicAuth("google", "google").
        AddURLEncodedForm(map[string]string{"data": "google"}).
        Send().
        Scan(&response)
    ...

POST with context (1/2)

package main

import (
    "github.com/monaco-io/request"
    "context"
)

func main() {
    c := request.Client{
        Context: context.Background(),
        URL:       "https://google.com",
        Method:    "POST",
        BasicAuth: request.BasicAuth{
            Username: "google",
            Password: "google",
        },
    }
    resp := c.Send()
    ...

POST with context (2/2)

package main

import (
    "github.com/monaco-io/request"
    "context"
)

func main() {
    var response interface{}

    resp := request.
        NewWithContext(context.TODO()).
        POST("http://httpbin.org/post").
        AddHeader(map[string]string{"Google": "google"}).
        AddBasicAuth("google", "google").
        AddURLEncodedForm(map[string]string{"data": "google"}).
        Send().
        Scan(&response)
    ...

Authorization

package main

import (
    "github.com/monaco-io/request"
)

func main() {
    c := request.Client{
        URL:       "https://google.com",
        Method:    "POST",
        BasicAuth: request.BasicAuth{
            Username: "google",
            Password: "google",
        },
    }
    resp := c.Send()
}

Timeout

package main

import (
    "github.com/monaco-io/request"
)

func main() {
    c := request.Client{
        URL:       "https://google.com",
        Method:    "POST",
        Timeout:   time.Second*10,
    }
}

Cookies

package main

import (
    "github.com/monaco-io/request"
)

func main() {
    c := request.Client{
        URL:       "https://google.com",
        CookiesMap: map[string]string{
            "cookie_name": "cookie_value",
        }
    }
}

TLS

package main

import (

    "github.com/monaco-io/request"
)

func main() {
    c := request.Client{
        URL:       "https://google.com",
        TLSConfig: &tls.Config{InsecureSkipVerify: true},
    }
}

License

MIT

最近版本更新:(数据更新于 2024-05-01 20:56:11)

2023-07-02 21:37:42 v1.0.16

2021-10-03 10:28:50 v1.0.15

2021-06-11 16:51:05 v1.0.14

2021-05-03 16:50:14 v1.0.13

2021-03-16 15:27:18 v1.0.12

2021-03-15 19:52:05 v1.0.11

2021-03-15 17:06:53 v1.0.10

2021-02-09 15:08:52 v1.0.9

2021-02-06 16:38:34 v1.0.8

2021-01-17 11:19:50 v1.0.7

主题(topics):

axios, client, go, golang, gorequest, http, net, request

monaco-io/request同语言 Go最近更新仓库

2024-05-19 09:38:45 initia-labs/initia

2024-05-18 23:53:18 usememos/memos

2024-05-18 17:58:05 SagerNet/sing-box

2024-05-18 06:38:00 dolthub/dolt

2024-05-18 04:35:49 containerd/containerd

2024-05-18 02:28:56 aws/aws-sdk-go