Script Services

From DreamFactory
Jump to: navigation, search

Script services are a type of service, defined by the scripting language used to execute the desired script (e.g. V8Js), that allow ad-hoc extension of DreamFactory's API by utilizing server-side scripting. In pre-2.x versions of the software, this was referred to as "custom" or "user" scripts. In 2.0, they get first-class treatment, similar to all other service types, allowing them to be used by role-service-access, packaging, etc. As such, they are managed via the api/v2/system/service API endpoint under the system service.

To see which script service types exists on a particular DreamFactory instance, the api/v2/system/service_type API endpoint and look for the ones with group set to 'Script'. Also, refer to the service types section of this documentation.

How It Works

The script configured as part of the Script service is run when the API endpoint for that service is called. Any additional URL resources (i.e. path after the service name), along with URL parameters, headers, and payload, are packaged into an event object and passed to the script execution context along with the platform object. Similar to event scripting, the event.response or exceptions thrown are sent back to the calling client.

Queueing

Like event scripts since release 2.3.0, service scripts can be queued for later execution. Setting the queued config setting to true will cause the script to be queued for later execution and HTTP status code of 202 Accepted to be returned immediately to the client.

{
	"id": 1,
	"name": "example",
	"label": "example script",
	"description": "example script for testing",
	"is_active": true,
	"type": "v8js",
	"mutable": true,
	"deletable": true,
	"created_date": "2016-08-19 15:00:42",
	"last_modified_date": "2016-08-19 19:00:42",
	"created_by_id": 1,
	"last_modified_by_id": 1,
	"config": {
		"service_id": 16,
		"queued": true,
		"content": "script content here",
		"config": null
	},
	"doc": {
		"service_id": 16,
		"format": 0,
		"content": "{\n\t\"paths\": {},\n\t\"definitions\": {},\n\t\"parameters\": {}\n}",
		"created_date": "2016-08-19 15:00:39",
		"last_modified_date": "2016-08-19 19:00:39"
	}
}