mirror of
https://github.com/42wim/matterbridge.git
synced 2024-12-18 17:12:37 +01:00
71a5b72aff
Signed-off-by: Gary Kim <gary@garykim.dev> |
||
---|---|---|
.. | ||
.gitignore | ||
.travis.yml | ||
CODE_OF_CONDUCT.md | ||
CONTRIBUTING.md | ||
doc.go | ||
go.mod | ||
go.sum | ||
LICENSE | ||
model.go | ||
README.md | ||
request.go | ||
resp.go | ||
url.go |
Request
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
- Intercept request and response
- 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
GET
package main
import (
"log"
"github.com/monaco-io/request"
)
func main() {
:= request.Client{
client : "https://google.com",
URL: "GET",
Method: map[string]string{"hello": "world"},
Params}
, err := client.Do()
resp
.Println(resp.Code, string(resp.Data), err)
log}
POST
package main
import (
"log"
"github.com/monaco-io/request"
)
func main() {
:= request.Client{
client : "https://google.com",
URL: "POST",
Method: map[string]string{"hello": "world"},
Params: []byte(`{"hello": "world"}`),
Body}
, err := client.Do()
resp
.Println(resp.Code, string(resp.Data), err)
log}
Content-Type
package main
import (
"log"
"github.com/monaco-io/request"
)
func main() {
:= request.Client{
client : "https://google.com",
URL: "POST",
Method: request.ApplicationXWwwFormURLEncoded, // default is "application/json"
ContentType}
, err := client.Do()
resp
.Println(resp.Code, string(resp.Data), err)
log}
Authorization
package main
import (
"log"
"github.com/monaco-io/request"
)
func main() {
:= request.Client{
client : "https://google.com",
URL: "POST",
Method: request.BasicAuth{
BasicAuth:"user_xxx",
Username:"pwd_xxx",
Password}, // xxx:xxx
}
, err := client.Do()
resp
.Println(resp.Code, string(resp.Data), err)
log}
Timeout
package main
import (
"log"
"github.com/monaco-io/request"
)
func main() {
:= request.Client{
client : "https://google.com",
URL: "POST",
Method: 10, // seconds
Timeout}
, err := client.Do()
resp
.Println(resp.Code, string(resp.Data), err)
log}
Cookies
package main
import (
"log"
"github.com/monaco-io/request"
)
func main() {
:= request.Client{
client : "https://google.com",
URL:[]*http.Cookie{
Cookies{
: "cookie_name",
Name: "cookie_value",
Value},
},
}
, err := client.Do()
resp
.Println(resp.Code, string(resp.Data), err)
log}