Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: links to content negotiation page

...

When a ruleset shares a KRL function and a user agent (i.e. browser) calls for that function through a /sky/cloud URL, the response is generally a string or a JSON object. The string option is useful when you want a person to see the result of the calculation directly, while the JSON option is best when it will be handled by Javascript code running within the user agent.

The pico engine also performs content negotiation which allows us to add a file extension after the function name (but before arguments in a query string) to indicate how we want the user agent to interpret a string response. Shown here, from top to bottom, with no extension, we see the string, but with a .html extension, the browser interprets that string as a selection box widget, and with a .txt extension, shows it as plain text.

...

Unlike text (whether plain or HTML), an image requires a binary response. The way to prepare a binary response in KRL is to use an Array containing octet values (as decimal numbers between 0 and 255 inclusive). This is supported by the pico engine as of version 0.45.5.

When the pico engine sees a .gif file extension, it will expect such an array, and will present the correct content type (image/gif) and send the bytes computed by your function as the response body. The user agent can then display the image by interpreting those bytes.

...

It is called for by a URL like this one. Notice the file extension .gif added to the function name (See the page on Content negotiation with HTTP).

Code Block
linenumberstrue
http://localhost:8080/sky/cloud/M8LoyVEVaCZenZvJD8GShG/net.sanbachs.counters/number.gif?n=007&bgcolor=[128,0,128]

...