HTTP

class Http.Failure(value, message)

An HTTP-specific Deferred.Deferred() failure result. Inherits Failure().

Http.Failure.Http.Failure.value

Failure value

Http.Failure.Http.Failure.message

Failure message

class Http.JsonDecodeFailure(value)

A Deferred.Deferred() error seen when JSON fails to parse

Http.JsonDecodeFailure.Http.JsonDecodeFailuremessage

Failure message

class Http.HeaderDict(headers)
Arguments
  • headers (variant()) – initial headers, as another HeaderDict or as an object.

A dict-like object with case insensitive lookup. Used to store HTTP request or HTTP response headers.

Http.HeaderDict.Http.HeaderDict.set(name, value)
Arguments
  • name (string()) – Header name

  • value (string()) – Header value

Sets header name.

Http.HeaderDict.Http.HeaderDict.unset(name)
Arguments
  • name (string()) – Header name

Unsets header name.

Http.HeaderDict.Http.HeaderDict.get(name)
Arguments
  • name (string()) – Header name

Returns

Header value or undefined.

Retrieves header name.

Http.HeaderDict.Http.HeaderDict.keys()
Returns

a list of defined header names

Http.HeaderDict.Http.HeaderDict.foreach(func)
Arguments
  • func (function()) – function to call

calls func(name, value) for each header.

class Http.QueryDict(values)
Arguments
  • values (variant()) – initial query; as an object (dict), another QueryDict, or a string (will be parsed as a querystring)

A dict-like object with case sensitive lookup. Used to store HTTP querystring. A given key may be specified multiple times.

Http.QueryDict.Http.QueryDict.set(key, value)
Arguments
  • key (string()) – Parameter key

  • value (string()) – Parameter value

Sets parameter key.

Http.QueryDict.Http.QueryDict.unset(key)
Arguments
  • key (string()) – Parameter key

Unsets parameter key.

Http.QueryDict.Http.QueryDict.get(key)
Arguments
  • key (string()) – Parameter key

Returns

Parameter value or undefined.

Retrieves last value for parameter key.

Http.QueryDict.Http.QueryDict.getAll(key)
Arguments
  • key (string()) – Parameter key

Returns

Parameter value or undefined.

Retrieves all parameters for key.

Http.QueryDict.Http.QueryDict.keys()
Returns

a list of defined parameter keys

Http.QueryDict.Http.QueryDict.foreach(func)
Arguments
  • func (function()) – function to call

calls func(key, value) for each parameter. func may be called multiple times with the same key if it has multiple values.

Http.QueryDict.Http.QueryDict.parse(qs)
Arguments
  • qs (string()) – A query string

Parses given query string and set all defined keys.

Http.QueryDict.Http.QueryDict.toString(sep)
Arguments
  • sep (string()) – Separator (defaults to “&”)

Returns

a formatted query string

Serializes the query string

Http.QueryDict.Http.QueryDict.toDict()
Returns

an object

Flattens the object as a plain object (dict). Multiple definitions for a key are lost. Only the last one is preserved.

Http.QueryDict.Http.QueryDict.append(args)
Arguments
  • args (variant()) – Arguments to add (as a QueryDict, a dict or a string)

Appends arguments from args to object.

class Http.URL(url)
Arguments
  • url (variant()) – initial url, as a string or as another URL.

A class to parse and edit URLs in place

Http.URL.Http.URL.protocol
Http.URL.Http.URL.host
Http.URL.Http.URL.user
Http.URL.Http.URL.password
Http.URL.Http.URL.port
Http.URL.Http.URL.path
Http.URL.Http.URL.anchor
Http.URL.Http.URL.qs

Query string as a QueryString() object. Editable in place.

Http.URL.Http.URL.toString()
Returns

URL string

class Http.Transaction(args)
Arguments
  • args (object()) – Transaction construction arguments

Arguments may be:

headers

A HeaderDict or a dict of headers to set in query

url

URL to open (mandatory)

method

HTTP method to use (defaults to GET)

body

Blob to send as body of request

Http.Transaction.Http.Transaction.body

Body blob

Http.Transaction.Http.Transaction.url

Target URL, as an URL() instance, may be edited in place.

Http.Transaction.Http.Transaction.method

HTTP method to use

Http.Transaction.Http.Transaction.headers

HTTP query headers, as a Http.HeaderDict(), may be edited in place.

Http.Transaction.Http.Transaction.send()
Returns

a sent Http.Query() instance with all properties at time of call.

Http.Transaction.Http.Transaction.factory(args)

Static method

Shortcut for new Http.Transaction(args).

Http.Transaction.Http.Transaction.debug_factory(args)

Static method

Shortcut for new Http.Transaction(args) with the subtle addition that all requests and responses are dumped with console.log.

Http.Transaction.factory({
    method: "post",
    url: "http://some.server.com/test/form",
    body: "test"
}).send().then(function (response) {
    console.log("Got response", response.body)
});
class Http.Request(method, url, headers)
Arguments
  • method (string()) – HTTP method

  • url (string()) – URL

  • headers (object()) – Query headers

A Deferred.Deferred() wrapping an XMLHttpRequest with given parameters.

Resolution value is a Http.Response().

Inherits Deferred.Deferred(). Should be created through Http.Transaction().

Http.Request.Http.Request.send(body)
Arguments
  • body (string()) – Body blob

class Http.Response()

A value spawned by Http.Request() objects.

Http.Response.Http.Response.isError()
Returns

Whether HTTP error code is to be considered as an error.

Http.Response.Http.Response.jsonParse(accept_null)
Arguments
  • accept_null (bool()) – Whether to consider an empty body as an acceptable value, yielding null.

Returns

a new Http.JsonResponse() instance or a new Http.JsonDecodeFailure() instance.

Http.Response.Http.Response.body

Body blob

Http.Response.Http.Response.status

HTTP status code

Http.Response.Http.Response.statusText

HTTP status text

Http.Response.Http.Response.headers

HTTP response headers, as a Http.HeaderDict().

class Http.JsonResponse()

An HTTP response with decoded JSON data.

Inherits Http.Response().

Http.JsonResponse.Http.JsonResponse.data

Decoded JSON object