Global Types

Global types are snap rules which define types that can be used in any other snap rule. These types are defined similar to types within any rule, with the exception that you cannot define functions or subroutines within them. These types are useful in cases where you'd like a safe function to return the result of a web service which does not have an implicitly known type, but you wish to define properties that you expect to be present in the result of that web service call to aid in retrieving those properties.

Learn more about "Type Conversion" on page 1 in general, to determine if a regular type or a global type is best for your needs.

 

Example

Let's suppose a web service, example.org/api/weather provides a result in JSON format with a city, state, zip code, and temperature. The web service blocks do not implicitly know that this is the format of the result, so normally you would need to use a map and arbitrarily access properties in the result. However, using a Global Type, you can define these properties.

In the safe function that calls this web service, you can specify WeatherResult as the return type.

Now, when you call that safe function, you can get expected properties in the dropdown when referencing the results.

Was this article helpful?