BBLANG

HTTP

bb:http:req(url|options, callback)
options : {
method:        // HTTP Method (default: "GET"),
url:           // URL to send request to
headers:       // HTTP Headers,
body:          // Request Body

form:          // Accepts data in map format and adds "Content-type: application/x-www-form-urlencoded" in the header

formData:      // Data to pass for a multipart/form-data request

json:          // sets body to json representation of the value and adds "Content-Type: application/json" to the header

auth:          // Basic Authentication data
oauth:         // Options for OAuth signing (default:  HMAC-SHA1)

encoding:      // encoding to be used on setEncoding header of response data (pass null for Buffer data)
}
headers : {
'header-name': 'header-value',
...
}

sending a json as form

form: {
name: "John Doe",
gender: "Male"
}

Basic Authentication

auth: {
user | username:
pass | password:
sendImmediately:
}

HTTP Response

{
status:          // response status code (1xx, 2xx, 3xx, 4xx, 5xx)
statusMessage:   // response status message (OK, Created, Forbidden, etc)
headers:         // response headers
body:            // reponse body
}

Examples

sending a post request with header fields and body.

bb:http:req({
method  : 'POST',
url     : 'https://example.com',
headers : {
'Accept-Charset': 'iso-8859-5, unicode-1-1; q=0.8',
],
form: {
username: "john"
name: "John Doe",
gender: "Male"
}
})

bb:http:get(url)

Same asbb:http:req(), but defaults tomethod: "GET".

Examples

bb:http:get("https://example.com")

bb:http:post(url)

Same asbb:http:req(), but defaults tomethod: "POST".

bb:http:post()

bb:http:put(url)

Same asbb:http:req(), but defaults tomethod: "PUT".

bb:http:put()

bb:http:patch(url)

Same asbb:http:req(), but defaults tomethod: "PATCH".

bb:http:patch()

bb:http:delete(url)

Same asbb:http:req(), but defaults tomethod: "DELETE".

bb:http:delete()

bb:http:head(url)

Same asbb:http:req(), but defaults tomethod: "HEAD".

bb:http:head()

MEMORY

bb:mem:get(key)

Retrieves the string representation of data corresponding to the given key.

Examples

// retrieves the data corresponding to "music".
bb:mem:get("music")

bb:mem:set(key, value)

Creates a new entry in memory corresponding to given key and sets the string representation of the given data as the value, or update the data to the given value if the key is already present.

bb:mem:set("keyName", data)

Examples

// sets the data corresponding to "music" as "lorem ipsum dolor sit amet".
bb:mem:set("music", "lorem ipsum dolor sit amet.")

bb:mem:del(key)

Deletes the memory entry corresponding to the given key.

bb:mem:del("keyName")

Examples

// deletes the row with key="music" from the database.
bb:mem:del("music")

UTILS

bb:log(message1, message2, message3, ...)

Logs outmessage1 message2 message3along with the datetime.

// logs out the request method, query parameters (if any) and body (if any).
bb:log('method', req.method, 'query', req.query, 'body', req.body)

Last updated