SWebService
Set up your web service
To setup your server for communication with space, in the root of your domain, on the port you are using, place a file named 'sinewave.space.scripting.txt' containing 'SPACE_OK'. E.g. http://somewhere.com/sinewave.space.scripting.txt - if this file is not present, you will be unable to use scripting to communicate with the domain. Note: you should use HTTPS for all API calls. You may also need to implement a CORS policy in your webserver headers.
Index
Functions Index
Functions
Get
void Get (string url, Closure onComplete, Table headers=null, float timeout=0)
Performs an HTTP[S] GET and invokes the callback with an SWebResponse containing the result.
url
string
The absolute URL to request. Must pass the domain whitelist check.
headers
Table (optional)
Supported keys: Content-Type, Bearer (maps to Authorization: Bearer <token>).
timeout
float (optional)
Timeout in seconds. 0 disables timeout.
Note:
This call automatically sends diagnostic headers:
X-Sinespace-Region-ID,X-Sinespace-Region-Name,X-Sinespace-Instance-ID,X-Sinespace-Script-Name,X-Sinespace-Runtime-Type,X-Sinespace-In-Editor, andX-Sinespace-Preview-Server.Domains must host
/sinewave.space.scripting.txtwith the contentSPACE_OKat the root for requests to proceed (see setup above).
Post
void Post (string url, string data, Closure onComplete, Table headers=null, float timeout=0)
Performs an HTTP[S] POST and invokes the callback with an SWebResponse containing the result.
url
string
The absolute URL to POST to. Must pass the domain whitelist check.
data
string
Request body. For JSON, provide a JSON string and set Content-Type accordingly.
headers
Table (optional)
Supported keys: Content-Type (defaults to application/x-www-form-urlencoded), Bearer (maps to Authorization: Bearer <token>).
timeout
float (optional)
Timeout in seconds. 0 disables timeout.
Note:
For JSON: set
Content-Type = application/jsonand send a JSON string body.The target domain must pass the whitelist check (
/sinewave.space.scripting.txtwithSPACE_OK).HTTPS is recommended; ensure the server sends appropriate CORS headers.
GetImage
SResource GetImage (string url, Closure onComplete=null, Table header=null, float timeout=0)
Returns a valid SResource for a image on a remote domain that can be used via e.g. SMaterial. While the image loads, it will be a white pixel that will be substituted with the real image once loaded.
url
string
The absolute image URL to load.
header
Table (optional)
Accepted but not used for images; pass nil. Reserved for future use.
timeout
float (optional)
Accepted but not used for images; pass 0. Reserved for future use.
Last updated
Was this helpful?

