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.

POST()

Usage

POST(url, body, contentType, charset)
POST(url, body, contentType)
POST(url, body)

Description
Send an HTTP POST request with the given body 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 POST() method will return a response object with the following structure:

Field Description Type
status HTTP status of the request Integer
headers Response headers Map
body Response body Map or String

If the MIME type of the response is application/json, the body field will contain the mapped response as a Structr object that can be accessed using the dot notation (e.g. result.body.result_count). Otherwise, the body field will contain the response as a string. (see the related articles for more information)

Note
Please note that the POST() 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().

Example

${POST('http://localhost:8082/structr/rest/User', '{name: "Tester"}')}

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 "POST()"

POST()

Send an HTTP POST request with the given body 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 POST() method will return a response object containing the reposonse headers, body and status code. The object has the following structure:

Field Description Type
status HTTP status of the request Integer
headers Response headers Map
body Response body Map or String
POST(url, body [, contentType = 'application/json' [, charset = 'utf-8' ] ] )