Create the FunctionFirst of all, you start out by simply writing a normal Script Function, like this:
Set the Access PolicyNext, you'll need to set the proper Access Policy for your Script Function. This is something you should give a bit of thought to, because it's a potential security risk.
For example, if you create a Script Function that returns a user's salary based on the user ID, making the Script Function public would mean that anyone would be able to read everybody else's salary, which is very likely not what you want.
Important! Using Access Policies only applies to Script Functions located in the Base Package. If the Script Function is in a different Package than Base, define an Entry Point instead.
Call the FunctionTo call the Script Function from the browser, simply use this URL in your browser:
The String value "Hello" will be assigned to the Script Function's parameter msg. This assignment is case sensitive. The Script Function's return value will be sent to the browser.
Check your ParametersIf the Script Function has additional parameters that you did not specify, their value will be null. In other words, if you want a parameter to be null, do not write something like this:
This is bad! It will set the parameter msg to the String null instead of to the null value.
In addition to Strings, you can also send ints, float values, and Boolean values.
HeadersIn our example, we also had to set some header values. In the Script Function that is being called using a URL, you can access the request and response objects using the functions HTTPREQUEST() and HTTPRESPONSE().
For example, if your function returned a JPEG image instead of text, you would set the proper content type like this: