Event Scripting
Line 9: | Line 9: | ||
Below are some example base (not including the '''type''' section) event names for various service types. | Below are some example base (not including the '''type''' section) event names for various service types. | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
===Database Services=== | ===Database Services=== | ||
* db.get, | * db.get, | ||
Line 77: | Line 49: | ||
* files.{file_path}.patch, | * files.{file_path}.patch, | ||
* files.{file_path}.delete, | * files.{file_path}.delete, | ||
+ | |||
+ | ===HTTP Services=== | ||
+ | HTTP Services, by default, fire no events unless there are paths defined in the Open-API/Swagger Specification. In that case, events are generated based on calls matching paths defined. | ||
+ | myservice.makes.count.get would be generated for a call to GET http://example.com/api/v2/myservice/makes/count. | ||
+ | |||
+ | ===SOAP Services=== | ||
+ | SOAP Services fire events based on the methods defined in the given WSDL file. For example, | ||
+ | myservice.call_method.post would be generated for a call to POST http://example.com/api/v2/myservice/call_method. | ||
===Auth Services=== | ===Auth Services=== | ||
Line 95: | Line 75: | ||
* user.custom.{id}.delete, | * user.custom.{id}.delete, | ||
− | === | + | ===System Resources=== |
− | + | The system service generates a lot of events, for example, for the root retrieval of resources... | |
− | + | * system.get | |
− | + | for common resources like admin, app, app_group, custom, cors, roles, services, users... | |
− | + | * system.service.get, | |
− | + | * system.service.post, | |
− | + | * system.service.patch, | |
+ | * system.service.delete, | ||
+ | * system.service.{id}.get, | ||
+ | * system.service.{id}.patch, | ||
+ | * system.service.{id}.delete, | ||
+ | some others include... | ||
+ | * system.cache.delete, | ||
+ | * system.cache.{service}.delete, | ||
+ | * system.config.get, | ||
+ | * system.config.post, | ||
+ | * system.constant.get, | ||
+ | * system.constant.{type}.get, | ||
+ | * system.environment.get, | ||
+ | * system.event.get, | ||
+ | * system.event.{event_name}.get, | ||
+ | * system.event.{event_name}.post, | ||
+ | * system.event.{event_name}.delete, | ||
+ | * system.service_type.get, | ||
+ | * system.script_type.get, | ||
+ | * system.package.get, | ||
+ | * system.package.post, | ||
==Scriptable Events== | ==Scriptable Events== | ||
Line 107: | Line 107: | ||
===Pre-Process=== | ===Pre-Process=== | ||
− | Following the [[DreamFactory/Overview|anatomy of an API call]], pre-process scripts are run after authentication and authorization, but before the API call is processed by to the handling service. | + | Following the [[DreamFactory/Overview|anatomy of an API call]], pre-process scripts are run after authentication and authorization, but before the API call is processed by to the handling service. This allows for the following scenarios... |
+ | * interrupting the API call before it is processed by throwing exceptions that are returned to the client, i.e. payload validation failures, etc., | ||
+ | * modifying the contents, parameters, or headers of the request to change how and/or what is processed, i.e. payload modification, etc. (see '''allow_event_modification''' in [[DreamFactory/Features/Scripting#Resources_Available_To_A_Script]]) | ||
+ | * perform additional functionality before the call is processed, i.e. external validation, tracking API usage, etc. | ||
===Post-Process=== | ===Post-Process=== | ||
− | Likewise, post-process scripts are run after the API call has been processed by the handling service, but before any final formatting and returning to the client. | + | Likewise, post-process scripts are run after the API call has been processed by the handling service, but before any final formatting and returning to the client. This allows for the following scenarios... |
+ | * modifying the contents, status code, or formatting of the response, i.e. adding related data from other services, or removing sensitive information, etc. (see '''allow_event_modification''' in [[DreamFactory/Features/Scripting#Resources_Available_To_A_Script]]) | ||
+ | * perform additional functionality before the response is returned to the client, i.e. triggering other services upon success or failure, logging, etc. | ||
===Queued (Coming Soon)=== | ===Queued (Coming Soon)=== | ||
Queued scripts on the other hand, do not and can not affect the processing of the original API call. Both the request and response of the event are saved along with the script and queued for later execution. | Queued scripts on the other hand, do not and can not affect the processing of the original API call. Both the request and response of the event are saved along with the script and queued for later execution. |
Revision as of 21:25, 21 July 2016
Event Scripting allows users to write scripts that run when certain system events happen. Scriptable events, a.k.a process events, are "fired" when certain parts of the API are called, externally by clients, or internally by other scripts. Events are generated for all services and most resources defined by those services.
Contents
Types of Events
API-generated events typically take the form ofservice[.resource].verb[.type]where
- service is the API name of the service,
- resource is the optional resource path ('/' replaced with '.') either statically defined, or using replacement parameters within {},
- verb is the HTTP verb used in the request
- type is the type of event, see below.
Below are some example base (not including the type section) event names for various service types.
Database Services
- db.get,
- db._schema.get,
- db._schema.post,
- db._schema.put,
- db._schema.patch,
- db._schema.{table_name}.get,
- db._schema.{table_name}.post,
- db._schema.{table_name}.put,
- db._schema.{table_name}.patch,
- db._schema.{table_name}.delete,
- db._schema.{table_name}.{field_name}.get,
- db._schema.{table_name}.{field_name}.put,
- db._schema.{table_name}.{field_name}.patch,
- db._schema.{table_name}.{field_name}.delete,
- db._table.get,
- db._table.{table_name}.get,
- db._table.{table_name}.post,
- db._table.{table_name}.put,
- db._table.{table_name}.patch,
- db._table.{table_name}.delete,
- db._table.{table_name}.{id}.get,
- db._table.{table_name}.{id}.put,
- db._table.{table_name}.{id}.patch,
- db._table.{table_name}.{id}.delete,
File Services
- files.get,
- files.post,
- files.patch,
- files.delete,
- files.{folder_path}.get,
- files.{folder_path}.post,
- files.{folder_path}.patch,
- files.{folder_path}.delete,
- files.{file_path}.get,
- files.{file_path}.post,
- files.{file_path}.put,
- files.{file_path}.patch,
- files.{file_path}.delete,
HTTP Services
HTTP Services, by default, fire no events unless there are paths defined in the Open-API/Swagger Specification. In that case, events are generated based on calls matching paths defined. myservice.makes.count.get would be generated for a call to GET http://example.com/api/v2/myservice/makes/count.
SOAP Services
SOAP Services fire events based on the methods defined in the given WSDL file. For example, myservice.call_method.post would be generated for a call to POST http://example.com/api/v2/myservice/call_method.
Auth Services
- user.get,
- user.password.post,
- user.profile.get,
- user.profile.post,
- user.register.post,
- user.session.get,
- user.session.post,
- user.session.delete,
- user.custom.get,
- user.custom.post,
- user.custom.patch,
- user.custom.delete,
- user.custom.{id}.get,
- user.custom.{id}.patch,
- user.custom.{id}.delete,
System Resources
The system service generates a lot of events, for example, for the root retrieval of resources...
- system.get
for common resources like admin, app, app_group, custom, cors, roles, services, users...
- system.service.get,
- system.service.post,
- system.service.patch,
- system.service.delete,
- system.service.{id}.get,
- system.service.{id}.patch,
- system.service.{id}.delete,
some others include...
- system.cache.delete,
- system.cache.{service}.delete,
- system.config.get,
- system.config.post,
- system.constant.get,
- system.constant.{type}.get,
- system.environment.get,
- system.event.get,
- system.event.{event_name}.get,
- system.event.{event_name}.post,
- system.event.{event_name}.delete,
- system.service_type.get,
- system.script_type.get,
- system.package.get,
- system.package.post,
Scriptable Events
Scriptable events currently fall under three categories, pre-process, post-process, and queued.
Pre-Process
Following the anatomy of an API call, pre-process scripts are run after authentication and authorization, but before the API call is processed by to the handling service. This allows for the following scenarios...
- interrupting the API call before it is processed by throwing exceptions that are returned to the client, i.e. payload validation failures, etc.,
- modifying the contents, parameters, or headers of the request to change how and/or what is processed, i.e. payload modification, etc. (see allow_event_modification in DreamFactory/Features/Scripting#Resources_Available_To_A_Script)
- perform additional functionality before the call is processed, i.e. external validation, tracking API usage, etc.
Post-Process
Likewise, post-process scripts are run after the API call has been processed by the handling service, but before any final formatting and returning to the client. This allows for the following scenarios...
- modifying the contents, status code, or formatting of the response, i.e. adding related data from other services, or removing sensitive information, etc. (see allow_event_modification in DreamFactory/Features/Scripting#Resources_Available_To_A_Script)
- perform additional functionality before the response is returned to the client, i.e. triggering other services upon success or failure, logging, etc.
Queued (Coming Soon)
Queued scripts on the other hand, do not and can not affect the processing of the original API call. Both the request and response of the event are saved along with the script and queued for later execution.