11.10. web: Web browsing, HTTP, and JSON capabilities.

Web browsing, HTTP, and JSON capabilities.

11.10.1. Browse

site Browse(String) :: Signal

Attempts to open a browser window in whatever user context is available, pointing to the URL given by the string argument. The URL must be absolute and well-formed. If the URL is malformed or unreachable, the call halts silently.

Example:

-- Open a browser window to the Google home page
Browse("http://www.google.com")

The HTTP site provides a simple mechanism to send GET and POST requests to a URL.

11.10.2. HTTP

site HTTP(java.net.URL) :: HTTP

Publishes an HTTP site which accepts HTTP requests on the given URL.

http.get() :: String

Performs a GET request on the URL used to create this HTTP site. The payload is empty. The response is published as a single string.

http.post(String, String) :: String

Performs a POST request on the URL used to create this HTTP site. The first string argument is used as the payload of the POST request. The second string argument is used as the request's Content-Type header value. The response is published as a single string.

http.url :: String

Publishes the URL used to create this HTTP site. If query parameters were used, they will be displayed in the query part of the URL, with the appropriate encoding.

11.10.3. HTTP

site HTTP(String) :: HTTP

Converts the given string to a URL U and then behaves as HTTP(U).

11.10.4. HTTP

site HTTP(String, {..}) :: HTTP

Takes a string S and a query record Q. Maps Q to a URL query string QS by translating each record binding to a query pair, escaping characters if necessary, and then behaves as HTTP(S+QS).

11.10.5. ReadJSON

site ReadJSON(String) :: Top

Parses a string representation of a JSON value, producing an Orc representation of that JSON value.

An Orc representation of a JSON value, called an OrcJSON value, is either a record of OrcJSON values (representing a JSON object), a list of OrcJSON values (representing a JSON array), or a literal value (representing a JSON primitive value).

ReadJSON and WriteJSON are mutual inverses. If S is a string representation of a JSON value, then WriteJSON(ReadJSON(S)) = S, modulo whitespace and object member ordering.

11.10.6. WriteJSON

site WriteJSON(Top) :: String

Serializes an Orc representation of a JSON value, producing a string representation of that JSON value.

An Orc representation of a JSON value, called an OrcJSON value, is either a record of OrcJSON values (representing a JSON object), a list of OrcJSON values (representing a JSON array), or a literal value (representing a JSON primitive value).

WriteJSON and ReadJSON are mutual inverses. If V is an Orc representation of a JSON value, then ReadJSON(WriteJSON(V)) = V.