Skip to content

Commit f843c88

Browse files
Add hosted service showcase with examples and documentation
1 parent 30b46cf commit f843c88

File tree

2 files changed

+127
-4
lines changed

2 files changed

+127
-4
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
###Pure
2+
// Define a simple function to be used by our hosted service
3+
function model::greet(name: String[1]): String[1]
4+
{
5+
'Hello, ' + $name + '! Welcome to the hosted service.'
6+
}
7+
8+
function model::processData(data: String[1]): String[1]
9+
{
10+
'Processed data: ' + $data
11+
}
12+
13+
###HostedService
14+
// Basic hosted service with UserList ownership
15+
HostedService model::BasicHostedService
16+
{
17+
pattern: '/api/greet/{name}';
18+
ownership: UserList { users: ['user1', 'user2'] };
19+
function: model::greet(String[1]):String[1];
20+
documentation: 'A simple hosted service that greets users by name';
21+
autoActivateUpdates: true;
22+
}
23+
24+
// Hosted service with Deployment ownership and stereotypes
25+
HostedService <<meta::pure::profiles::doc.doc>> {doc.doc='Example with deployment ownership'} model::DeploymentHostedService
26+
{
27+
pattern: '/api/process/{data}';
28+
ownership: Deployment { identifier: '12345' };
29+
function: model::processData(String[1]):String[1];
30+
documentation: 'A hosted service that processes data with deployment ownership';
31+
autoActivateUpdates: false;
32+
}
33+
34+
// Hosted service with post-deployment actions
35+
HostedService model::AdvancedHostedService
36+
{
37+
pattern: '/api/advanced/{param}';
38+
ownership: UserList { users: ['admin'] };
39+
function: model::processData(String[1]):String[1];
40+
documentation: 'Advanced hosted service with post-deployment actions';
41+
autoActivateUpdates: true;
42+
actions:
43+
{
44+
SlackNotify
45+
{
46+
channel: '#deployments';
47+
message: 'Hosted service has been deployed';
48+
}
49+
}
50+
}
Lines changed: 77 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,80 @@
11
---
2-
title: Hosted service activator
3-
description:
4-
development: true
2+
title: Hosted Service Activator
3+
description: Examples of hosted service definitions and features
54
---
65

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

Comments
 (0)