http

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2023 License: AGPL-3.0 Imports: 17 Imported by: 0

Documentation

Overview

Package http the http JS implementation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewResponse

func NewResponse(vm *goja.Runtime, res *http.Response) goja.Value

NewResponse returns a new Response

Types

type FileData

type FileData struct {
	Data     []byte
	Filename string
}

FileData wraps the file data and filename

type FormData

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

FormData provides a way to construct a set of key/value pairs representing form fields and their values. which can be sent using the http() method and encoding type were set to "multipart/form-data". Implement the https://developer.mozilla.org/en-US/docs/Web/API/FormData

func (*FormData) Append

func (f *FormData) Append(name string, value any, filename string) (ret goja.Value)

Append method of the FormData interface appends a new value onto an existing key inside a FormData object, or adds the key if it does not already exist.

func (*FormData) Delete

func (f *FormData) Delete(name string)

Delete method of the FormData interface deletes a key and its value(s) from a FormData object.

func (*FormData) Entries

func (f *FormData) Entries() any

Entries method returns an iterator which iterates through all key/value pairs contained in the FormData.

func (*FormData) Get

func (f *FormData) Get(name string) any

Get method of the FormData interface returns the first value associated with a given key from within a FormData object. If you expect multiple values and want all of them, use the getAll() method instead.

func (*FormData) GetAll

func (f *FormData) GetAll(name string) any

GetAll method of the FormData interface returns all the values associated with a given key from within a FormData object.

func (*FormData) Has

func (f *FormData) Has(name string) bool

Has method of the FormData interface returns whether a FormData object contains a certain key.

func (*FormData) Keys

func (f *FormData) Keys() any

Keys method returns an iterator which iterates through all keys contained in the FormData. The keys are strings.

func (*FormData) Set

func (f *FormData) Set(name string, value any, filename string)

Set method of the FormData interface sets a new value for an existing key inside a FormData object, or adds the key/value if it does not already exist.

func (*FormData) Values

func (f *FormData) Values() any

Values method returns an iterator which iterates through all values contained in the FormData.

type Http

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

Http module for fetching resources (including across the network).

func (*Http) Get

func (h *Http) Get(call goja.FunctionCall, vm *goja.Runtime) (ret goja.Value)

Get Make a GET request with URL and optional headers.

func (*Http) Head

func (h *Http) Head(call goja.FunctionCall, vm *goja.Runtime) (ret goja.Value)

Head Make a HEAD request with URL and optional headers.

func (*Http) Post

func (h *Http) Post(call goja.FunctionCall, vm *goja.Runtime) (ret goja.Value)

Post Make a POST request with URL, optional body, optional headers. Send POST with multipart: http.post(url, new FormData({'bytes': new Uint8Array([0]).buffer})) Send POST with x-www-form-urlencoded: http.post(url, new URLSearchParams({'key': 'foo', 'value': 'bar'})) Send POST with json: http.post(url, {'key': 'foo'})

func (*Http) Request

func (h *Http) Request(call goja.FunctionCall, vm *goja.Runtime) (ret goja.Value)

Request Make a request with method and URL, optional body, optional headers.

func (*Http) Template

func (h *Http) Template(call goja.FunctionCall, vm *goja.Runtime) (ret goja.Value)

Template Make a request with an HTTP template, template argument.

type Module

type Module struct{}

Module js module

func (*Module) Exports

func (*Module) Exports() any

Exports returns module instance

type NativeFormData

type NativeFormData struct{}

NativeFormData js global module

func (*NativeFormData) Exports

func (*NativeFormData) Exports() any

Exports returns module instance

func (*NativeFormData) Global

func (*NativeFormData) Global()

Global it is a global module

type NativeURLSearchParams

type NativeURLSearchParams struct{}

NativeURLSearchParams Native module

func (*NativeURLSearchParams) Exports

func (*NativeURLSearchParams) Exports() any

Exports instance URLSearchParams module

func (*NativeURLSearchParams) Global

func (*NativeURLSearchParams) Global()

Global it is a global module

type Response

type Response struct {
	Headers    http.Header // response headers.
	Status     int         // HTTP status code.
	StatusText string      // HTTP status message corresponding to the HTTP status code.
	Ok         bool        // true if response Status in the range 200-299.
	// contains filtered or unexported fields
}

Response wraps the given response

func (*Response) Bytes

func (r *Response) Bytes(_ goja.FunctionCall, vm *goja.Runtime) goja.Value

Bytes returns an ArrayBuffer.

func (*Response) Json

func (r *Response) Json() any

Json parsing the body text as JSON.

func (*Response) JsonEncodable

func (r *Response) JsonEncodable() any

JsonEncodable allows custom JSON encoding by JSON.stringify()

func (*Response) String

func (r *Response) String() string

String body resolves with a string. The response is always decoded using UTF-8.

type URLSearchParams

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

The URLSearchParams defines utility methods to work with the query string of a URL, which can be sent using the http() method and encoding type were set to "application/x-www-form-url". Implement the https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams

func (*URLSearchParams) Append

func (u *URLSearchParams) Append(name, value string)

Append method of the URLSearchParams interface appends a specified key/value pair as a new search parameter.

func (*URLSearchParams) Delete

func (u *URLSearchParams) Delete(name string)

Delete method of the URLSearchParams interface deletes the given search parameter and all its associated values, from the list of all search parameters.

func (*URLSearchParams) Entries

func (u *URLSearchParams) Entries() any

Entries method of the URLSearchParams interface returns an iterator allowing iteration through all key/value pairs contained in this object. The iterator returns key/value pairs in the same order as they appear in the query string. The key and value of each pair are string objects.

func (*URLSearchParams) ForEach

func (u *URLSearchParams) ForEach(call goja.FunctionCall, vm *goja.Runtime) (ret goja.Value)

ForEach method of the URLSearchParams interface allows iteration through all values contained in this object via a callback function.

func (*URLSearchParams) Get

func (u *URLSearchParams) Get(name string) any

Get method of the URLSearchParams interface returns the first value associated to the given search parameter.

func (*URLSearchParams) GetAll

func (u *URLSearchParams) GetAll(name string) []string

GetAll method of the URLSearchParams interface returns all the values associated with a given search parameter as an array.

func (*URLSearchParams) Has

func (u *URLSearchParams) Has(name string) bool

Has method of the URLSearchParams interface returns a boolean value that indicates whether a parameter with the specified name exists.

func (*URLSearchParams) Keys

func (u *URLSearchParams) Keys() []string

Keys method of the URLSearchParams interface returns an iterator allowing iteration through all keys contained in this object. The keys are string objects.

func (*URLSearchParams) Set

func (u *URLSearchParams) Set(name, value string)

Set method of the URLSearchParams interface sets the value associated with a given search parameter to the given value. If there were several matching values, this method deletes the others. If the search parameter doesn't exist, this method creates it.

func (*URLSearchParams) Sort

func (u *URLSearchParams) Sort()

Sort method sorts all key/value pairs contained in this object in place and returns undefined.

func (*URLSearchParams) ToString

func (u *URLSearchParams) ToString() string

ToString method of the URLSearchParams interface returns a query string suitable for use in a URL.

func (*URLSearchParams) Values

func (u *URLSearchParams) Values() [][]string

Values method of the URLSearchParams interface returns an iterator allowing iteration through all values contained in this object. The values are string objects.

Jump to

Keyboard shortcuts

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