You have been redirected from an outdated version of the article. Below is the content available on this topic. To view the old article click here.

GET()

Usage

GET(url, contentType, selector)
GET(url, contentType)
GET(url)

Description
Sends an HTTP GET request with the given body and an optional content type to the given url. This method can be used to make HTTP requests from within the Structr Server, triggered by a frontend control like a button etc. The optional selector parameter can be used to select a subset of the HTML response, as documented in the JSOUP Cookbook.

The GET() method will return the literal HTTP response without the headers. If you are interested in the response headers, use the HEAD() function.

Note
Please note that the GET() method will not be executed in the security context of the current user. The request will be made by the Structr server, without any user authentication or additional information. If you want to access external protected resources, you will need to authenticate the request using add_header(). (see the related articles for more information)

Example

${GET('http://localhost:8082/structr/rest/User')}

results in

{body={code=401.0, message=Forbidden}, status=401, headers={Date=Tue, 22 Dec 2015 16:39:20 GMT, Content-Type=application/json; charset=utf-8, Content-Length=44, Server=Jetty(9.2.9.v20150224)}}

Search results for "GET()"

GET()

This method makes a server-side HTTP GET request to the given url and returns the literal HTTP response (without the headers - If you are interested in the response headers, use the HEAD() function).

The contentType only serves as way to handle certain formats differently:
- The value text/html parses the returned text as HTML using JSOUP and allows for an optional third parameter selector to select a subset of the HTML response, as documented in the JSOUP Cookbook.
- From version 3.5 onwards, GET() supports binary content by setting the contentType parameter to application/octet-stream. (This is helpful when creating files - see below example)
- Any other value for contentType simply returns the literal HTTP response

GET(url [, contentType [, username, password]])

GET(url, 'text/html', selector)
GET(url, 'application/octet-stream' [, username, password]])

get()

Returns the value for the given property key from the given entity. This method will print an error message if the first parameter is null / not accessible. See get_or_null() for a more tolerant get method.

get(entity, propertyKey)

request_store_get()

Retrieves a stored value from the request level store.

request_store_get(key)

application_store_get()

Retrieves a stored value from the application level store.

application_store_get(key)

JavaScript

In any other than the JavaScript context, you are required to use get() and call() to access built-in functions and constants. This results in code like the following example.