|  | 
| 1 | 1 | --- | 
| 2 |  | -title: Hosted service activator | 
| 3 |  | -description: | 
| 4 |  | -development: true | 
|  | 2 | +title: Hosted Service Activator | 
|  | 3 | +description: Examples of hosted service definitions and features | 
| 5 | 4 | --- | 
| 6 | 5 | 
 | 
| 7 |  | -TODO: Some dummy description | 
|  | 6 | +# Hosted Service Activator | 
|  | 7 | + | 
|  | 8 | +This showcase demonstrates how to define and configure hosted services in Legend. Hosted services allow you to expose Pure functions as HTTP endpoints with specific URL patterns. | 
|  | 9 | + | 
|  | 10 | +## Basic Features | 
|  | 11 | + | 
|  | 12 | +A hosted service definition requires the following elements: | 
|  | 13 | + | 
|  | 14 | +- **pattern**: The URL pattern for accessing the service, which can include path parameters | 
|  | 15 | +- **ownership**: Who owns the service (UserList or Deployment) | 
|  | 16 | +- **function**: The Pure function to be executed when the service is called | 
|  | 17 | +- **documentation**: Description of what the service does | 
|  | 18 | +- **autoActivateUpdates**: Whether updates to the service should be automatically activated | 
|  | 19 | + | 
|  | 20 | +## Example 1: Basic Hosted Service with UserList Ownership | 
|  | 21 | + | 
|  | 22 | +``` | 
|  | 23 | +HostedService model::BasicHostedService | 
|  | 24 | +{ | 
|  | 25 | +  pattern: '/api/greet/{name}'; | 
|  | 26 | +  ownership: UserList { users: ['user1', 'user2'] }; | 
|  | 27 | +  function: model::greet(String[1]):String[1]; | 
|  | 28 | +  documentation: 'A simple hosted service that greets users by name'; | 
|  | 29 | +  autoActivateUpdates: true; | 
|  | 30 | +} | 
|  | 31 | +``` | 
|  | 32 | + | 
|  | 33 | +This example defines a hosted service that: | 
|  | 34 | +- Is accessible at the URL pattern `/api/greet/{name}` | 
|  | 35 | +- Is owned by a list of users ('user1' and 'user2') | 
|  | 36 | +- Executes the `model::greet` function when called | 
|  | 37 | +- Has automatic activation of updates enabled | 
|  | 38 | + | 
|  | 39 | +## Example 2: Hosted Service with Deployment Ownership | 
|  | 40 | + | 
|  | 41 | +``` | 
|  | 42 | +HostedService <<meta::pure::profiles::doc.doc>> {doc.doc='Example with deployment ownership'} model::DeploymentHostedService | 
|  | 43 | +{ | 
|  | 44 | +  pattern: '/api/process/{data}'; | 
|  | 45 | +  ownership: Deployment { identifier: '12345' }; | 
|  | 46 | +  function: model::processData(String[1]):String[1]; | 
|  | 47 | +  documentation: 'A hosted service that processes data with deployment ownership'; | 
|  | 48 | +  autoActivateUpdates: false; | 
|  | 49 | +} | 
|  | 50 | +``` | 
|  | 51 | + | 
|  | 52 | +This example shows: | 
|  | 53 | +- Using stereotypes and tagged values for additional metadata | 
|  | 54 | +- Deployment ownership with an identifier | 
|  | 55 | +- Disabling automatic activation of updates | 
|  | 56 | + | 
|  | 57 | +## Example 3: Advanced Features with Post-Deployment Actions | 
|  | 58 | + | 
|  | 59 | +``` | 
|  | 60 | +HostedService model::AdvancedHostedService | 
|  | 61 | +{ | 
|  | 62 | +  pattern: '/api/advanced/{param}'; | 
|  | 63 | +  ownership: UserList { users: ['admin'] }; | 
|  | 64 | +  function: model::processData(String[1]):String[1]; | 
|  | 65 | +  documentation: 'Advanced hosted service with post-deployment actions'; | 
|  | 66 | +  autoActivateUpdates: true; | 
|  | 67 | +  actions: | 
|  | 68 | +  { | 
|  | 69 | +    SlackNotify | 
|  | 70 | +    { | 
|  | 71 | +      channel: '#deployments'; | 
|  | 72 | +      message: 'Hosted service has been deployed'; | 
|  | 73 | +    } | 
|  | 74 | +  } | 
|  | 75 | +} | 
|  | 76 | +``` | 
|  | 77 | + | 
|  | 78 | +This example demonstrates: | 
|  | 79 | +- Post-deployment actions (SlackNotify in this case) | 
|  | 80 | +- Configuration of the post-deployment action | 
0 commit comments