Creating web APIs: explaining script item types in Arnica WebScript
October 14, 2015 by Igor Lozhkin
Arnica WebScript is a part of the Arnica Platform
, which has been designed for creating web APIs programmed in a mix of contemporary languages - C#, PHP, SQL, and others.
Web APIs serving common projects/tasks are collected under the umbrella of a script set. Script set is a collection of script items, each representing a script, programmed in its own language. Regardless of the language, script items are classified by script type. Script item type is an important property, which determines the role of the item in the script set.
The following are supported script item types in Arnica WebScript:
- Public script - script item, which is exposed via public API interface and thus may be called from other programs. This is the only script item type, which allows interaction with external programs
- Constructor - script item, which is executed when public script is invoked, before the public script executes its own code. Constructors may execute any validation logic or prepare any data for the public script. There may be multiple constructors executed before the public script; they are executed in the sequence of their Position Number property. If a constructor returns False, execution terminates at that point, and public script code is not invoked. Public script may optionally disable execution of the constructor code
- Destructor - script item, which is executed after the public script. Multiple destructors may be defined; they are executed in the sequence determined by the Position Number property. In multiple destructors case, if one destructor returns False, then subsequent destructors are not executed. Destructors are designed to finalize the logic for the public script - for example, publish events, send notifications, update database flags for long-running processes, etc.
- Library - this is the script, which technically is not executed by itself but rather is associated with other scripts (public, constructor or destructor script types), and serves as an extension of the code. For example, "codebehind " in asp.net model, or PHP libraries, etc.
Arnica WebScript allows mixing script items with different languages under a single script set, with the idea that each script item would use appropriate language to get its job done in the most efficient way.
Below is an example of a script set with different types of script items:
Arnica WebScript is part of the Arnica Platform
and foundation for the platform's web APIs implementation.