Package: Kernel-HTTP
Class: HTTPClient
Introduction
Environment: container
HTTPClient is a HTTP client library.
It has the following attributes:
hostthe host of the requestportthe port of the requesturlthe url of the requesttimeoutthe timeout of the requestcontentsthe contents of the requestcontentTypethe content type of the requestmethodthe http request method.
It has the following methods:
queryAt:put:Add key equals value as an HTTP query parameter to the current request.headerAt:put:Add key equals value as an HTTP header to the current request.executeexecute the requestgetexecute a get requestputexecute a put requestpostexecute a post requestdeleteexecute a delete requestheadexecute a head request
You can use it to make HTTP requests to a server.
for example, for a HTTP get:
and for a HTTP post:
The result is a Dictionary which has three keys:
statusThe http status code.headersThe http headers.responseThe http response body. It wil be parsed as JSON if possible, otherwise it will be a string.
For example, you can check the status code like this:
Sometimes, the http request may raise an error for a failure request, we can catch error like this:
Instance Method
Category: accessing - request
contentType- Get the contentType of the HTTPClient.contentType:- Set the contentType of the HTTPClient.contents- Get the contents of the HTTPClient.contents:- Set the contents of the HTTPClient.headerAt:put:- Set key equals value in the HTTP header of the current request.For example:
host- Get the host of the HTTPClient.host:- Set the host of the HTTPClient.method- Get the method of the HTTPClient.method:- Set the method of the HTTPClient.port- Get the port of the HTTPClient.port:- Set the port of the HTTPClient.queryAt:put:- Add key equals value as an HTTP query parameter to the current request.If a key is already present, its corresponding value will be replaced.
For example:
timeout- Get the timeout of the HTTPClient.timeout:- Set the timeout of the HTTPClient.url- Get the url of the HTTPClient.url:- Set the url of the HTTPClient.
Category: operations
delete- Execute an HTTP DELETE the request set up and return the response #contents.execute- Execute the currently set up request to generate a response. Return the #contents of the response, if any.get- Execute an HTTP GET the request set up and return the response #contents.head- Execute a HTTP HEAD on the request set up and return nil.post- Execute an HTTP POST the request set up and return the response #contents.put- Execute an HTTP PUT the request set up and return the response #contents.
Class: UUIDGenerator
Introduction
Environment: container
The UUIDGenerator generates UUIDs, this can be used by following the syntax below
Class Method
Category: accessing
next- returns a new UUID string.
Last updated
Was this helpful?