http

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2021 License: MIT Imports: 12 Imported by: 11

README

http

http defines an HTTP client implementation

Functions

delete(url,params={},headers={},body="",form_body={},json_body={},auth=()) response

perform an HTTP DELETE request, returning a response

parameters:

name type description
url string url to request
headers dict optional. dictionary of headers to add to request
body string optional. raw string body to provide to the request
form_body dict optional. dict of values that will be encoded as form data
json_body any optional. json data to supply as a request. handy for working with JSON-API's
auth tuple optional. (username,password) tuple for http basic authorization
get(url,params={},headers={},auth=()) response

perform an HTTP GET request, returning a response

parameters:

name type description
url string url to request
headers dict optional. dictionary of headers to add to request
auth tuple optional. (username,password) tuple for http basic authorization
options(url,params={},headers={},body="",form_body={},json_body={},auth=()) response

perform an HTTP OPTIONS request, returning a response

parameters:

name type description
url string url to request
headers dict optional. dictionary of headers to add to request
body string optional. raw string body to provide to the request
form_body dict optional. dict of values that will be encoded as form data
json_body any optional. json data to supply as a request. handy for working with JSON-API's
auth tuple optional. (username,password) tuple for http basic authorization
patch(url,params={},headers={},body="",form_body={},json_body={},auth=()) response

perform an HTTP PATCH request, returning a response

parameters:

name type description
url string url to request
headers dict optional. dictionary of headers to add to request
body string optional. raw string body to provide to the request
form_body dict optional. dict of values that will be encoded as form data
json_body any optional. json data to supply as a request. handy for working with JSON-API's
auth tuple optional. (username,password) tuple for http basic authorization
post(url,params={},headers={},body="",form_body={},json_body={},auth=()) response

perform an HTTP POST request, returning a response

parameters:

name type description
url string url to request
headers dict optional. dictionary of headers to add to request
body string optional. raw string body to provide to the request
form_body dict optional. dict of values that will be encoded as form data
json_body any optional. json data to supply as a request. handy for working with JSON-API's
auth tuple optional. (username,password) tuple for http basic authorization
put(url,params={},headers={},body="",form_body={},json_body={},auth=()) response

perform an HTTP PUT request, returning a response

parameters:

name type description
url string url to request
headers dict optional. dictionary of headers to add to request
body string optional. raw string body to provide to the request
form_body dict optional. dict of values that will be encoded as form data
json_body any optional. json data to supply as a request. handy for working with JSON-API's
auth tuple optional. (username,password) tuple for http basic authorization

Types

response

the result of performing a http request

Fields

name type description
url string the url that was ultimately requested (may change after redirects)
status_code int response status code (for example: 200 == OK)
headers dict dictionary of response headers
encoding string transfer encoding. example: "octet-stream" or "application/json"

Methods

body() string

output response body as a string

json()

attempt to parse resonse body as json, returning a JSON-decoded result

Documentation

Overview

Package http defines a module for doing http operations in starlark

outline: http
  http defines an HTTP client implementation
  path: http
  functions:
    get(url,params={},headers={},auth=()) response
      perform an HTTP GET request, returning a response
      params:
        url string
          url to request
        headers dict
          optional. dictionary of headers to add to request
        auth tuple
          optional. (username,password) tuple for http basic authorization
    put(url,params={},headers={},body="",form_body={},form_encoding="",json_body={},auth=()) response
      perform an HTTP PUT request, returning a response
      params:
        url string
          url to request
        headers dict
          optional. dictionary of headers to add to request
        body string
          optional. raw string body to provide to the request
        form_body dict
          optional. dict of values that will be encoded as form data
        form_encoding string
          optional. `application/x-www-form-url-encoded` (default) or `multipart/form-data`
        json_body any
          optional. json data to supply as a request. handy for working with JSON-API's
        auth tuple
          optional. (username,password) tuple for http basic authorization
    post(url,params={},headers={},body="",form_body={},form_encoding="",json_body={},auth=()) response
      perform an HTTP POST request, returning a response
      params:
        url string
          url to request
        headers dict
          optional. dictionary of headers to add to request
        body string
          optional. raw string body to provide to the request
        form_body dict
          optional. dict of values that will be encoded as form data
        form_encoding string
          optional. `application/x-www-form-url-encoded` (default) or `multipart/form-data`
        json_body any
          optional. json data to supply as a request. handy for working with JSON-API's
        auth tuple
          optional. (username,password) tuple for http basic authorization
    delete(url,params={},headers={},body="",form_body={},form_encoding="",json_body={},auth=()) response
      perform an HTTP DELETE request, returning a response
      params:
        url string
          url to request
        headers dict
          optional. dictionary of headers to add to request
        body string
          optional. raw string body to provide to the request
        form_body dict
          optional. dict of values that will be encoded as form data
        form_encoding string
          optional. `application/x-www-form-url-encoded` (default) or `multipart/form-data`
        json_body any
          optional. json data to supply as a request. handy for working with JSON-API's
        auth tuple
          optional. (username,password) tuple for http basic authorization
    patch(url,params={},headers={},body="",form_body={},form_encoding="",json_body={},auth=()) response
      perform an HTTP PATCH request, returning a response
      params:
        url string
          url to request
        headers dict
          optional. dictionary of headers to add to request
        body string
          optional. raw string body to provide to the request
        form_body dict
          optional. dict of values that will be encoded as form data
        form_encoding string
          optional. `application/x-www-form-url-encoded` (default) or `multipart/form-data`
        json_body any
          optional. json data to supply as a request. handy for working with JSON-API's
        auth tuple
          optional. (username,password) tuple for http basic authorization
    options(url,params={},headers={},body="",form_body={},form_encoding="",json_body={},auth=()) response
      perform an HTTP OPTIONS request, returning a response
      params:
        url string
          url to request
        headers dict
          optional. dictionary of headers to add to request
        body string
          optional. raw string body to provide to the request
        form_body dict
          optional. dict of values that will be encoded as form data
        form_encoding string
          optional. `application/x-www-form-url-encoded` (default) or `multipart/form-data`
        json_body any
          optional. json data to supply as a request. handy for working with JSON-API's
        auth tuple
          optional. (username,password) tuple for http basic authorization

  types:
    response
      the result of performing a http request
      fields:
        url string
          the url that was ultimately requested (may change after redirects)
        status_code int
          response status code (for example: 200 == OK)
        headers dict
          dictionary of response headers
        encoding string
          transfer encoding. example: "octet-stream" or "application/json"
      methods:
        body() string
          output response body as a string
        json()
          attempt to parse resonse body as json, returning a JSON-decoded result

Index

Constants

View Source
const ModuleName = "http.star"

ModuleName defines the expected name for this Module when used in starlark's load() function, eg: load('http.star', 'http')

Variables

This section is empty.

Functions

func AsString

func AsString(x starlark.Value) (string, error)

AsString unquotes a starlark string value

func LoadModule

func LoadModule() (starlark.StringDict, error)

LoadModule creates an http Module

Types

type Module

type Module struct {
	// contains filtered or unexported fields
}

Module joins http tools to a dataset, allowing dataset to follow along with http requests

func (*Module) StringDict

func (m *Module) StringDict() starlark.StringDict

StringDict returns all module methods in a starlark.StringDict

func (*Module) Struct

func (m *Module) Struct() *starlarkstruct.Struct

Struct returns this module's methods as a starlark Struct

type RequestGuard

type RequestGuard interface {
	Allowed(req *http.Request) error
}

RequestGuard controls access to http by checking before making requests if Allowed returns an error the request will be denied

var (
	// Client is the http client used to create the http module. override with
	// a custom client before calling LoadModule
	Client = http.DefaultClient
	// Guard is a global RequestGuard used in LoadModule. override with a custom
	// implementation before calling LoadModule
	Guard RequestGuard
)

type Response

type Response struct {
	http.Response
}

Response represents an HTTP response, wrapping a go http.Response with starlark methods

func (*Response) HeadersDict

func (r *Response) HeadersDict() *starlark.Dict

HeadersDict flops

func (*Response) JSON

func (r *Response) JSON(thread *starlark.Thread, _ *starlark.Builtin, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error)

JSON attempts to parse the response body as JSON

func (*Response) Struct

func (r *Response) Struct() *starlarkstruct.Struct

Struct turns a response into a *starlark.Struct

func (*Response) Text

func (r *Response) Text(thread *starlark.Thread, _ *starlark.Builtin, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error)

Text returns the raw data as a string

Jump to

Keyboard shortcuts

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