Ballerina API Documentation

Functions of ballerina.net.http package

public function <Request req> addHeader(string key, string value)

Adds a transport header to the request

Receiver:

Receiver NameData TypeDescription
reqRequestA request message

Parameters:

Parameter NameData TypeDescription
keystringThe header name
valuestringThe header value

public function <Request req> clone() (Request)

Clones and creates a new instance of a request message

Receiver:

Receiver NameData TypeDescription
reqRequestA request message

Return Parameters:

Return VariableData TypeDescription
Requestrequest: The new instance of the request message

public function <Request req> createSessionIfAbsent() (Session)

Gets the session struct for valid id, otherwise create new

Receiver:

Receiver NameData TypeDescription
reqRequestThe request message

Return Parameters:

Return VariableData TypeDescription
SessionSession: HTTP session struct

public function <Request req> getBinaryPayload() (blob)

Gets the request payload in blob format

Receiver:

Receiver NameData TypeDescription
reqRequestA request message

Return Parameters:

Return VariableData TypeDescription
blobblob: The blob representation of the message payload

public function <Request req> getContentLength() (int)

Gets the Content-Length header from the request

Receiver:

Receiver NameData TypeDescription
reqRequestA request message

Return Parameters:

Return VariableData TypeDescription
intint: length of the message

public function <Request req> getFormParams() (map)

Gets formParam map from HTTP request

Receiver:

Receiver NameData TypeDescription
reqRequestThe request message

Return Parameters:

Return VariableData TypeDescription
mapmap: The map of form params

public function <Request req> getHeader(string headerName) (string, boolean)

Gets a transport header from the request

Receiver:

Receiver NameData TypeDescription
reqRequestA request message

Parameters:

Parameter NameData TypeDescription
headerNamestringThe header name

Return Parameters:

Return VariableData TypeDescription
stringstring: The header value
booleanstring: The header value

public function <Request req> getHeaders() (string[])

Gets transport headers from the request

Receiver:

Receiver NameData TypeDescription
reqRequestA request message

Return Parameters:

Return VariableData TypeDescription
string[]string[]: The header values

public function <Request req> getJsonPayload() (json)

Gets the request payload in JSON format

Receiver:

Receiver NameData TypeDescription
reqRequestA request message

Return Parameters:

Return VariableData TypeDescription
jsonjson: The JSON reresentation of the message payload

public function <Request req> getMethod() (string)

Gets the HTTP method from the request

Receiver:

Receiver NameData TypeDescription
reqRequestA request message

Return Parameters:

Return VariableData TypeDescription
stringstring: http method value

public function <Request req> getProperty(string propertyName) (string)

Retrieve a request property

Receiver:

Receiver NameData TypeDescription
reqRequestA request message

Parameters:

Parameter NameData TypeDescription
propertyNamestringThe name of the property

Return Parameters:

Return VariableData TypeDescription
stringstring: The property value

public function <Request req> getQueryParams() (map)

Gets queryParam map from HTTP request

Receiver:

Receiver NameData TypeDescription
reqRequestThe request message

Return Parameters:

Return VariableData TypeDescription
mapmap: The map of query params

public function <Request req> getRequestURL() (string)

Gets the request URL from the request

Receiver:

Receiver NameData TypeDescription
reqRequestThe request message

Return Parameters:

Return VariableData TypeDescription
stringstring: The request URL value

public function <Request req> getSession() (Session)

Gets the session struct for valid id

Receiver:

Receiver NameData TypeDescription
reqRequestThe request message

Return Parameters:

Return VariableData TypeDescription
SessionSession: HTTP session struct

public function <Request req> getStringPayload() (string)

Gets the request payload in string format

Receiver:

Receiver NameData TypeDescription
reqRequestA request message

Return Parameters:

Return VariableData TypeDescription
stringstring: The string representation of the message payload

public function <Request req> getXmlPayload() (xml)

Gets the request payload in XML format

Receiver:

Receiver NameData TypeDescription
reqRequestThe request message

Return Parameters:

Return VariableData TypeDescription
xmlxml: The XML representation of the message payload

public function <Request req> removeAllHeaders()

Removes all transport headers from the message

Receiver:

Receiver NameData TypeDescription
reqRequestA request message

public function <Request req> removeHeader(string key)

Removes a transport header from the request

Receiver:

Receiver NameData TypeDescription
reqRequestA request message

Parameters:

Parameter NameData TypeDescription
keystringThe header name

public function <Request req> setContentLength(int contentLength)

Sets the Content-Length header on the request

Receiver:

Receiver NameData TypeDescription
reqRequestA request message

Parameters:

Parameter NameData TypeDescription
contentLengthintLength of the message

public function <Request req> setHeader(string key, string value)

Sets the value of a transport header

Receiver:

Receiver NameData TypeDescription
reqRequestA request message

Parameters:

Parameter NameData TypeDescription
keystringThe header name
valuestringThe header value

public function <Request req> setJsonPayload(json payload)

Sets the request payload using a JSON object

Receiver:

Receiver NameData TypeDescription
reqRequestA request message

Parameters:

Parameter NameData TypeDescription
payloadjsonThe JSON payload object

public function <Request req> setProperty(string propertyName, string propertyValue)

Sets a request property

Receiver:

Receiver NameData TypeDescription
reqRequestA request message

Parameters:

Parameter NameData TypeDescription
propertyNamestringThe name of the property
propertyValuestringThe value of the property

public function <Request req> setStringPayload(string payload)

Sets the request payload using a string object

Receiver:

Receiver NameData TypeDescription
reqRequestA request message

Parameters:

Parameter NameData TypeDescription
payloadstringThe string payload object

public function <Request req> setXmlPayload(xml payload)

Sets the message payload using an XML object

Receiver:

Receiver NameData TypeDescription
reqRequestA request message

Parameters:

Parameter NameData TypeDescription
payloadxmlThe XML payload object

public function <Response res> addHeader(string key, string value)

Adds a transport header to the response

Receiver:

Receiver NameData TypeDescription
resResponseThe response message

Parameters:

Parameter NameData TypeDescription
keystringThe header name
valuestringThe header value

public function <Response res> clone() (Response)

Clones and creates a new instance of a response message

Receiver:

Receiver NameData TypeDescription
resResponseThe response message

Return Parameters:

Return VariableData TypeDescription
Responseresponse: The new instance of the response message

public function <Response res> forward(Response resp)

Forwards client service response directly to the caller.

Receiver:

Receiver NameData TypeDescription
resResponseThe response message

Parameters:

Parameter NameData TypeDescription
respResponseThe new instance of the response message

public function <Response res> getBinaryPayload() (blob)

Gets the response payload in blob format

Receiver:

Receiver NameData TypeDescription
resResponseThe response message

Return Parameters:

Return VariableData TypeDescription
blobblob: The blob representation of the message payload

public function <Response res> getContentLength() (int)

Gets the Content-Length header from the response

Receiver:

Receiver NameData TypeDescription
resResponseThe response message

Return Parameters:

Return VariableData TypeDescription
intint: length of the message

public function <Response res> getHeader(string headerName) (string, boolean)

Gets a transport header from the response

Receiver:

Receiver NameData TypeDescription
resResponseThe response message

Parameters:

Parameter NameData TypeDescription
headerNamestringThe header name

Return Parameters:

Return VariableData TypeDescription
stringstring: The header value
booleanstring: The header value

public function <Response res> getHeaders() (string[])

Gets transport headers from the response

Receiver:

Receiver NameData TypeDescription
resResponseThe response message

Return Parameters:

Return VariableData TypeDescription
string[]string[]: The header values

public function <Response res> getJsonPayload() (json)

Gets the response payload in JSON format

Receiver:

Receiver NameData TypeDescription
resResponseThe response message

Return Parameters:

Return VariableData TypeDescription
jsonjson: The JSON reresentation of the message payload

public function <Response res> getProperty(string propertyName) (string)

Retrieve a response property

Receiver:

Receiver NameData TypeDescription
resResponseThe response message

Parameters:

Parameter NameData TypeDescription
propertyNamestringThe name of the property

Return Parameters:

Return VariableData TypeDescription
stringstring: The property value

public function <Response res> getStatusCode() (int)

Gets the HTTP status code from the response

Receiver:

Receiver NameData TypeDescription
resResponseThe response message

Return Parameters:

Return VariableData TypeDescription
intint: http status code

public function <Response res> getStringPayload() (string)

Gets the response payload in string format

Receiver:

Receiver NameData TypeDescription
resResponseThe response message

Return Parameters:

Return VariableData TypeDescription
stringstring: The string representation of the message payload

public function <Response res> getXmlPayload() (xml)

Gets the response payload in XML format

Receiver:

Receiver NameData TypeDescription
resResponseThe response message

Return Parameters:

Return VariableData TypeDescription
xmlxml: The XML representation of the message payload

public function <Response res> removeAllHeaders()

Removes all transport headers from the response

Receiver:

Receiver NameData TypeDescription
resResponseThe response message

public function <Response res> removeHeader(string key)

Removes a transport header from the response

Receiver:

Receiver NameData TypeDescription
resResponseThe response message

Parameters:

Parameter NameData TypeDescription
keystringThe header name

public function <Response res> send()

Sends outbound response to the caller.

Receiver:

Receiver NameData TypeDescription
resResponseThe response message

public function <Response res> setContentLength(int contentLength)

Sets the Content-Length header on the response

Receiver:

Receiver NameData TypeDescription
resResponseThe response message

Parameters:

Parameter NameData TypeDescription
contentLengthintLength of the message

public function <Response res> setHeader(string key, string value)

Sets the value of a transport header

Receiver:

Receiver NameData TypeDescription
resResponseThe response message

Parameters:

Parameter NameData TypeDescription
keystringThe header name
valuestringThe header value

public function <Response res> setJsonPayload(json payload)

Sets the response payload using a JSON object

Receiver:

Receiver NameData TypeDescription
resResponsereq: The response message

Parameters:

Parameter NameData TypeDescription
payloadjsonThe JSON payload object

public function <Response res> setProperty(string propertyName, string propertyValue)

Sets a response property

Receiver:

Receiver NameData TypeDescription
resResponseThe response message

Parameters:

Parameter NameData TypeDescription
propertyNamestringThe name of the property
propertyValuestringThe value of the property

public function <Response res> setReasonPhrase(string reasonPhrase)

Sets a custom HTTP Reason phrase

Receiver:

Receiver NameData TypeDescription
resResponseThe response message

Parameters:

Parameter NameData TypeDescription
reasonPhrasestringReason phrase value

public function <Response res> setStatusCode(int statusCode)

Sets the HTTP StatusCode on the response

Receiver:

Receiver NameData TypeDescription
resResponseThe response message

Parameters:

Parameter NameData TypeDescription
statusCodeintHTTP status code

public function <Response res> setStringPayload(string payload)

Sets the response payload using a string object

Receiver:

Receiver NameData TypeDescription
resResponseThe response message

Parameters:

Parameter NameData TypeDescription
payloadstringThe string payload object

public function <Response res> setXmlPayload(xml payload)

Sets the response payload using an XML object

Receiver:

Receiver NameData TypeDescription
resResponseThe response message

Parameters:

Parameter NameData TypeDescription
payloadxmlThe XML payload object

public function <Session session> getAttribute(string attributeKey) (any)

Gets the session attribute

Receiver:

Receiver NameData TypeDescription
sessionSessionA session struct

Parameters:

Parameter NameData TypeDescription
attributeKeystringHTTPSession attribute key

Return Parameters:

Return VariableData TypeDescription
anyany: HTTPSession attribute value

public function <Session session> getAttributeNames() (string[])

Gets the session attribute names

Receiver:

Receiver NameData TypeDescription
sessionSessionA session struct

Return Parameters:

Return VariableData TypeDescription
string[]string[]: HTTPSession attribute name array

public function <Session session> getCreationTime() (int)

Gets the session creation time

Receiver:

Receiver NameData TypeDescription
sessionSessionA session struct

Return Parameters:

Return VariableData TypeDescription
intint: HTTPSession creation time

public function <Session session> getId() (string)

Gets the session id

Receiver:

Receiver NameData TypeDescription
sessionSessionA session struct

Return Parameters:

Return VariableData TypeDescription
stringstring: HTTPSession id

public function <Session session> getLastAccessedTime() (int)

Gets the session last accessed time

Receiver:

Receiver NameData TypeDescription
sessionSessionA session struct

Return Parameters:

Return VariableData TypeDescription
intint: HTTPSession last accessed time

public function <Session session> getMaxInactiveInterval() (int)

Gets the session max inactive interval

Receiver:

Receiver NameData TypeDescription
sessionSessionA session struct

Return Parameters:

Return VariableData TypeDescription
intint: HTTPSession max inactive interval

public function <Session session> invalidate()

Gets the session attribute

Receiver:

Receiver NameData TypeDescription
sessionSessionA session struct

public function <Session session> isNew() (boolean)

Gets the session status

Receiver:

Receiver NameData TypeDescription
sessionSessionA session struct

Return Parameters:

Return VariableData TypeDescription
booleanboolean: HTTPSession status

public function <Session session> removeAttribute(string attributeKey)

Remove the session attribute

Receiver:

Receiver NameData TypeDescription
sessionSessionA session struct

Parameters:

Parameter NameData TypeDescription
attributeKeystringHTTPSession attribute key

public function <Session session> setAttribute(string attributeKey, any attributeValue)

Sets session attributes to the message

Receiver:

Receiver NameData TypeDescription
sessionSessionA session struct

Parameters:

Parameter NameData TypeDescription
attributeKeystringHTTPSession attribute key
attributeValueanyHTTPSession attribute Value

public function <Session session> setMaxInactiveInterval(int timeInterval)

Sets session max inactive interval

Receiver:

Receiver NameData TypeDescription
sessionSessionA session struct

Parameters:

Parameter NameData TypeDescription
timeIntervalintHTTPSession max inactive interval


Connectors of ballerina.net.http package

public connector HttpClient (string serviceUri, Options connectorOptions)

Http client connector for outbound http requests

Parameters:

Parameter NameData TypeDescription
serviceUristringUrl of the service
connectorOptionsOptionsconnector options

Actions:

action delete(string path, Request req)

The DELETE action implementation of the HTTP connector

Parameters:

Parameter NameData TypeDescription
pathstringResource path
reqRequestA request message

Return Parameters:

Return VariableData TypeDescription
Responseresponse: The response message
HttpConnectorErrorresponse: The response message

action execute(string httpVerb, string path, Request req)

Invokes an HTTP call with the specified HTTP verb.

Parameters:

Parameter NameData TypeDescription
httpVerbstringHTTP verb value
pathstringResource path
reqRequestA request message

Return Parameters:

Return VariableData TypeDescription
Responseresponse: The response message
HttpConnectorErrorresponse: The response message

action forward(string path, Request req)

forward action can be used to invoke an http call with incoming request httpVerb

Parameters:

Parameter NameData TypeDescription
pathstringRequest path
reqRequestA request message

Return Parameters:

Return VariableData TypeDescription
Responseresponse: The response message
HttpConnectorErrorresponse: The response message

action get(string path, Request req)

GET action implementation of the HTTP Connector

Parameters:

Parameter NameData TypeDescription
pathstringRequest path
reqRequestA request message

Return Parameters:

Return VariableData TypeDescription
Responseresponse: The response message
HttpConnectorErrorresponse: The response message

action head(string path, Request req)

The HEAD action implementation of the HTTP Connector.

Parameters:

Parameter NameData TypeDescription
pathstringResource path
reqRequestA request message

Return Parameters:

Return VariableData TypeDescription
Responseresponse: The response message
HttpConnectorErrorresponse: The response message

action patch(string path, Request req)

The PATCH action implementation of the HTTP Connector.

Parameters:

Parameter NameData TypeDescription
pathstringResource path
reqRequestA request message

Return Parameters:

Return VariableData TypeDescription
Responseresponse: The response message
HttpConnectorErrorresponse: The response message

action post(string path, Request req)

The POST action implementation of the HTTP Connector.

Parameters:

Parameter NameData TypeDescription
pathstringResource path
reqRequestA request message

Return Parameters:

Return VariableData TypeDescription
Responseresponse: The response message
HttpConnectorErrorresponse: The response message

action put(string path, Request req)

The PUT action implementation of the HTTP Connector.

Parameters:

Parameter NameData TypeDescription
pathstringResource path
reqRequestA request message

Return Parameters:

Return VariableData TypeDescription
Responseresponse: The response message
HttpConnectorErrorresponse: The response message


Structs of ballerina.net.http package

public struct HttpConnectorError

HttpConnectorError struct represents an error occured during the HTTP client invocation

Fields:

Field NameData TypeDescription
msgstringAn error message explaining about the error
causeerrorThe error that caused HttpConnectorError to get thrown
stackTraceStackFrame[]Represents the invocation stack when HttpConnectorError is thrown
statusCodeintHTTP status code

public struct Options

Options struct represents options to be used for HTTP client invocation

Fields:

Field NameData TypeDescription
portintPort number of the remote service
endpointTimeoutintEndpoint timeout value in millisecond
chunkDisabledbooleanDisable chunking
followRedirectsFollowRedirectsRedirect related options
sslSSLssl/tls related options
retryConfigRetryRetry related options

public struct Request

Represents a http request message

public struct Response

Represents a http response message

public struct Session

Represents a http Session


Annotations of ballerina.net.http package

annotation configuration

Configuration for HTTP service

Attributes:

Attribute NameData TypeDescription
hoststring
portint
httpsPortint
basePathstring
keyStoreFilestring
keyStorePasswordstring
trustStoreFilestring
trustStorePasswordstring
sslVerifyClientstring
certPasswordstring
sslEnabledProtocolsstring
ciphersstring
sslProtocolstring
allowOriginsstring[]
allowCredentialsboolean
allowMethodsstring[]
allowHeadersstring[]
maxAgeint
exposeHeadersstring[]
webSocketwebSocket

annotation resourceConfig

Configuration for HTTP resource

Attributes:

Attribute NameData TypeDescription
methodsstring[]
pathstring
consumesstring[]
producesstring[]
allowOriginsstring[]
allowCredentialsboolean
allowMethodsstring[]
allowHeadersstring[]
maxAgeint
exposeHeadersstring[]

annotation webSocket

Annotation to upgrade connection from http to ws in the same base path.

Attributes:

Attribute NameData TypeDescription
upgradePathstring
serviceNamestring


Menu

  • Functions
    • <Request> addHeader(string key, string value)
    • <Request> clone() (Request )
    • <Request> createSessionIfAbsent() (Session )
    • <Request> getBinaryPayload() (blob )
    • <Request> getContentLength() (int )
    • <Request> getFormParams() (map )
    • <Request> getHeader(string headerName) (string , boolean )
    • <Request> getHeaders() (string[] )
    • <Request> getJsonPayload() (json )
    • <Request> getMethod() (string )
    • <Request> getProperty(string propertyName) (string )
    • <Request> getQueryParams() (map )
    • <Request> getRequestURL() (string )
    • <Request> getSession() (Session )
    • <Request> getStringPayload() (string )
    • <Request> getXmlPayload() (xml )
    • <Request> removeAllHeaders()
    • <Request> removeHeader(string key)
    • <Request> setContentLength(int contentLength)
    • <Request> setHeader(string key, string value)
    • <Request> setJsonPayload(json payload)
    • <Request> setProperty(string propertyName, string propertyValue)
    • <Request> setStringPayload(string payload)
    • <Request> setXmlPayload(xml payload)
    • <Response> addHeader(string key, string value)
    • <Response> clone() (Response )
    • <Response> forward(Response resp)
    • <Response> getBinaryPayload() (blob )
    • <Response> getContentLength() (int )
    • <Response> getHeader(string headerName) (string , boolean )
    • <Response> getHeaders() (string[] )
    • <Response> getJsonPayload() (json )
    • <Response> getProperty(string propertyName) (string )
    • <Response> getStatusCode() (int )
    • <Response> getStringPayload() (string )
    • <Response> getXmlPayload() (xml )
    • <Response> removeAllHeaders()
    • <Response> removeHeader(string key)
    • <Response> send()
    • <Response> setContentLength(int contentLength)
    • <Response> setHeader(string key, string value)
    • <Response> setJsonPayload(json payload)
    • <Response> setProperty(string propertyName, string propertyValue)
    • <Response> setReasonPhrase(string reasonPhrase)
    • <Response> setStatusCode(int statusCode)
    • <Response> setStringPayload(string payload)
    • <Response> setXmlPayload(xml payload)
    • <Session> getAttribute(string attributeKey) (any )
    • <Session> getAttributeNames() (string[] )
    • <Session> getCreationTime() (int )
    • <Session> getId() (string )
    • <Session> getLastAccessedTime() (int )
    • <Session> getMaxInactiveInterval() (int )
    • <Session> invalidate()
    • <Session> isNew() (boolean )
    • <Session> removeAttribute(string attributeKey)
    • <Session> setAttribute(string attributeKey, any attributeValue)
    • <Session> setMaxInactiveInterval(int timeInterval)
  • Connectors
    • HttpClient (string serviceUri, Options connectorOptions)
      • delete(Request req)
      • execute(string path, Request req)
      • forward(Request req)
      • get(Request req)
      • head(Request req)
      • patch(Request req)
      • post(Request req)
      • put(Request req)
  • Structs
    • HttpConnectorError
    • Options
    • Request
    • Response
    • Session
  • Annotations
    • configuration
    • resourceConfig
    • webSocket

Copyright 2017 Ballerina API Documentation