requests

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2021 License: MIT Imports: 6 Imported by: 0

README

requests

created by Austin Poor

A simple requests library written in Go.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HTTPMethod

type HTTPMethod int
const (
	GET HTTPMethod = iota
	POST
	PUT
	DELETE
	OPTIONS
	HEAD
	CONNECT
	TRACE
	PATCH
)

func (HTTPMethod) String

func (m HTTPMethod) String() string

Convert an HTTPMethod to it's string format

type Request

type Request struct {
	URL     string            // URL to send the request to
	Method  HTTPMethod        // HTTP method to use
	Headers map[string]string // Headers to send with the request
	Body    []byte            // Body to send with the request
	Timeout time.Duration     // Timeout for the request
}

func (*Request) DelHeader

func (req *Request) DelHeader(name string)

Deletes a header value from the request headers if it exists. Normalizes the key to lowercase before deleting.

func (*Request) GetHeader

func (req *Request) GetHeader(name string) (string, bool)

Get a header value from the request. Normalizes the key to lowercase before checking. Returns the value of the header and whether it exists.

func (*Request) MustSend

func (req *Request) MustSend() *Response

Send the HTTP request and panic if an error is returned. (Calls Send() internally)

func (*Request) Send

func (req *Request) Send() (*Response, error)

Send the HTTP request with the supplied parameters

func (*Request) SetHeader

func (req *Request) SetHeader(name, value string)

Sets a header value in the request. Normalizes the key before setting (converts to lowercase).

type Response

type Response struct {
	Ok         bool              // Was the request successful? (Status codes: 200-399)
	StatusCode int               // HTTP response status code
	Headers    map[string]string // HTTP Response headers
	Body       []byte            // HTTP Response body
}

func (*Response) GetHeader

func (resp *Response) GetHeader(name string) (string, bool)

Get a header value from the response if it exists. Normalizes the key to lowercase before checking. Returns the value of the header and whether it exists.

func (*Response) JSON

func (resp *Response) JSON() (map[string]interface{}, error)

Unmarshall the response body into a map

Jump to

Keyboard shortcuts

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