Skip to content

Commit 219b2f1

Browse files
committed
Adds Demo Application
1 parent c9ba917 commit 219b2f1

File tree

4 files changed

+108
-0
lines changed

4 files changed

+108
-0
lines changed

README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,55 @@ http://localhost:8080
4343
```
4444
http://localhost:8080/swagger-ui/index.html
4545
```
46+
47+
## Demo Application
48+
49+
The [demo-application](demo-application) folder contains a simple applications, that consumes the custom API _(`/custom-api/MyApi`)_. The `/custom-api/MyApi` is a TypeScript API, that exposes the `io.dirigible.samples.MyFacade` Java class. The Java class has both `static` and `instance` methods.
50+
51+
**demo-application/demo.ts**
52+
```ts
53+
import { response } from "sdk/http";
54+
import { MyApi } from "/custom-api/MyApi";
55+
56+
const myApiInstance = new MyApi();
57+
58+
const firstNumber = myApiInstance.add(5, 3);
59+
const secondNumber = myApiInstance.multiply(5, 3);
60+
const customMethod = myApiInstance.customMethod("sample-custom-stack");
61+
const greetingMessage = MyApi.greet();
62+
63+
const data = {
64+
firstNumber: firstNumber,
65+
secondNumber: secondNumber,
66+
customMethod: customMethod,
67+
greetingMessage: greetingMessage,
68+
};
69+
70+
response.println(JSON.stringify(data, null, 2));
71+
```
72+
73+
**/custom-api/MyApi**
74+
```ts
75+
const MyFacade = Java.type("io.dirigible.samples.MyFacade");
76+
77+
export class MyApi {
78+
79+
private facadeInstance = new MyFacade();
80+
81+
public static greet(): string {
82+
return MyFacade.greet();
83+
}
84+
85+
public add(a: number, b: number): number {
86+
return this.facadeInstance.add(a, b);
87+
}
88+
89+
public multiply(a: number, b: number): number {
90+
return this.facadeInstance.multiply(a, b);
91+
}
92+
93+
public customMethod(input: string): string {
94+
return this.facadeInstance.customMethod(input);
95+
}
96+
}
97+
```

demo-application/demo.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { response } from "sdk/http";
2+
import { MyApi } from "/custom-api/MyApi";
3+
4+
const myApiInstance = new MyApi();
5+
6+
const firstNumber = myApiInstance.add(5, 3);
7+
const secondNumber = myApiInstance.multiply(5, 3);
8+
const customMethod = myApiInstance.customMethod("sample-custom-stack");
9+
const greetingMessage = MyApi.greet();
10+
11+
const data = {
12+
firstNumber: firstNumber,
13+
secondNumber: secondNumber,
14+
customMethod: customMethod,
15+
greetingMessage: greetingMessage,
16+
};
17+
18+
response.println(JSON.stringify(data, null, 2));

demo-application/project.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"guid": "demo-application",
3+
"actions": [
4+
{
5+
"name": "Build TypeScript",
6+
"commands": [
7+
{
8+
"os": "unix",
9+
"command": "tsc"
10+
},
11+
{
12+
"os": "windows",
13+
"command": "cmd /c tsc"
14+
}
15+
],
16+
"registry": "true"
17+
}
18+
]
19+
}

demo-application/tsconfig.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"compilerOptions": {
3+
"module": "ESNext",
4+
"target": "ES6",
5+
"moduleResolution": "Node",
6+
"lib": [
7+
"ESNext",
8+
"DOM"
9+
],
10+
"paths": {
11+
"sdk/*": [
12+
"../modules/src/*"
13+
]
14+
},
15+
"types": [
16+
"../modules/types"
17+
]
18+
}
19+
}

0 commit comments

Comments
 (0)