requests

package module
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2023 License: GPL-3.0 Imports: 36 Imported by: 21

README

Requests

Go Report Card CodeFactor FOSSA Status

Logo

Install

go get github.com/cvelab/requests

Demo

import (
    "fmt"
    "github.com/cvelab/requests"
    "github.com/cvelab/requests/ext"
    "github.com/cvelab/requests/types"
)

func main() {
    // Requests Bearer Token
    auth := types.BasicAuth{Username: "o94KGT3MlbT...", Password: "fNbL2ukEGyvuGSM7bAuoq..."}
    data := types.Dict{
        "grant_type": "client_credentials",
    }
    resp := requests.Post("https://api.twitter.com/oauth2/token", ext.Auth(auth), ext.Data(data))
    
    // Requests with Twitter API 2.0
    if resp != nil && resp.Ok {
        fmt.Println(resp.Json())
        token := types.BearerAuth{Token: resp.Json().Get("access_token").Str}
        resp2 := requests.Get("https://api.twitter.com/2/users/by/username/Sariel_D", ext.Auth(token))
        fmt.Println(resp2.Json())
    }
}

Document

Licenses

MIT License

FOSSA Status

Documentation

Index

Constants

View Source
const DefaultTimeout = 5 // time.Second
View Source
const Version = "v1.1.15"

Variables

This section is empty.

Functions

func PrepareRequest

func PrepareRequest(proto string, method string, url string, params types.Dict, headers types.Dict, cookies types.Dict, form types.Dict, json map[string]any, files types.Dict, stream io.Reader, auth types.AuthInter) (error, *prepareRequest)

Types

type Request

type Request struct {
	*http.Request
}

type Response

type Response struct {
	*http.Response
	Session *Session

	History []*Response
	Html    string
	Ok      bool
	Raw     *[]byte
	// contains filtered or unexported fields
}

func Delete

func Delete(url string, ext ...types.Ext) *Response

func Get

func Get(url string, ext ...types.Ext) *Response
func Head(url string, ext ...types.Ext) *Response

func Options

func Options(url string, ext ...types.Ext) *Response

func Post

func Post(url string, ext ...types.Ext) *Response

func Put

func Put(url string, ext ...types.Ext) *Response

func (*Response) ContentType

func (resp *Response) ContentType() string

func (*Response) CustomRender

func (resp *Response) CustomRender(targetListenerCallbacks []func(ev interface{}), flags []chromedp.ExecAllocatorOption, actions ...chromedp.Action) *Response

CustomRender 支持各类Action接口实现

func (*Response) Json

func (resp *Response) Json() *gjson.Result

func (*Response) Render

func (resp *Response) Render() *Response

func (*Response) Save

func (resp *Response) Save(savePath string) (string, error)

func (*Response) Snapshot

func (resp *Response) Snapshot(fullscreen bool, png bool) *[]byte

Snapshot quality: false->jpeg | true->png

func (*Response) Text

func (resp *Response) Text() string

func (*Response) Title

func (resp *Response) Title() string

func (*Response) URLs

func (resp *Response) URLs() []string

func (*Response) XPath

func (resp *Response) XPath() *parser.XpathNode

type Session

type Session struct {
	types.ExtensionPackage
	Client *http.Client
	// contains filtered or unexported fields
}

func HTMLSession

func HTMLSession() *Session

func (*Session) Delete

func (s *Session) Delete(url string, ext ...types.Ext) *Response

func (*Session) Get

func (s *Session) Get(url string, ext ...types.Ext) *Response

func (*Session) Head

func (s *Session) Head(url string, ext ...types.Ext) *Response

func (*Session) Options

func (s *Session) Options(url string, ext ...types.Ext) *Response

func (*Session) Post

func (s *Session) Post(url string, ext ...types.Ext) *Response

func (*Session) Put

func (s *Session) Put(url string, ext ...types.Ext) *Response

func (*Session) RegisterHook

func (s *Session) RegisterHook(key string, hook types.Hook) error

func (*Session) Send

func (s *Session) Send(prep *prepareRequest) *Response

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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