HttpRequest
classin packageklyn.net
public class HttpRequest extends Object
└ HttpRequest

Immutable HTTP request description.

HttpRequest carries the URL, method, headers and optional body to be sent by HttpClient.

import klyn.net

request = HttpRequest("https://example.com/api", "POST").withBody({"name": "klyn"})
print(request.method)
Properties
Modifier and Type Member Description
public readonly property body
body as Object
Optional request body.
public readonly property headers
headers as SortedMap<String, String>
Returns a snapshot of the request headers.
public readonly property method
method as String
Normalized HTTP method.
public readonly property url
url as URL
Target HTTP or HTTPS URL.
Inherited Properties
propertyInherited Properties from Object: type
Constructors
Modifier and Type Member Description
public HttpRequest
HttpRequest(url as Object, method as String = "GET", headers as Map<String, String> = null, body as Object = null) throws Exception
Creates an immutable HTTP request.
Methods
Modifier and Type Member Description
public override toString
toString() as String
No summary.
public withBody
withBody(body as Object) as HttpRequest throws Exception
Returns a copy with a different request body.
public withHeader
withHeader(name as String, value as String) as HttpRequest throws Exception
Returns a copy with one header added or replaced.
public withMethod
withMethod(method as String) as HttpRequest throws Exception
Returns a copy with a different HTTP method.
public withoutHeader
withoutHeader(name as String) as HttpRequest throws Exception
Returns a copy without one header.
Inherited Methods
methodInherited Methods from Object: deepCopy, fromJson, hash, toDict, toJson, toMap, toString, toXml