@travetto/web-rpc 6.0.0-rc.7 → 6.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +60 -0
  2. package/package.json +4 -4
package/README.md CHANGED
@@ -29,3 +29,63 @@ Options:
29
29
  -m, --module <module> Module to run for
30
30
  -h, --help display help for command
31
31
  ```
32
+
33
+ ## Example
34
+
35
+ **Code: Example Controller**
36
+ ```typescript
37
+ import { Controller, Get } from '@travetto/web';
38
+
39
+ @Controller('/draft')
40
+ export class DraftController {
41
+
42
+ @Get('/suggest/tags')
43
+ async getTags(q?: string): Promise<string[]> {
44
+ return [.../* To fill in */[q ?? '']];
45
+ }
46
+ }
47
+ ```
48
+
49
+ This controller is a basic example of an invokable endpoint.
50
+
51
+ **Config: resources/application.yml**
52
+ ```yaml
53
+ web.rpc:
54
+ clients:
55
+ - type: web
56
+ output: ./api-client
57
+ ```
58
+
59
+ The configuration, while not necessary, makes it easy to consistently configure and generate the appropriate client.
60
+
61
+ **Terminal: Example Client Generation**
62
+ ```bash
63
+ npx trv web:rpc-client config
64
+ ```
65
+
66
+ You can manually invoke the client generation, but once configured, it will run automatically when running the web server as well.
67
+
68
+ **Code: Example API Factory**
69
+ ```typescript
70
+ import { clientFactory } from './rpc';
71
+ import type { DraftController } from '../.trv/types/node_modules/@travetto-doc/web-rpc/src/controller.js';
72
+
73
+ export const factory = clientFactory<{
74
+ DraftController: DraftController;
75
+ }>();
76
+ ```
77
+
78
+ The api factory relies on the type information generated by the compiler, and so this file is the only configuration needed to connect your controllers to the rpc functionality.
79
+
80
+ **Code: Example Client Usage**
81
+ ```javascript
82
+ import { factory } from '../api-client/factory';
83
+
84
+ const client = factory({ url: 'http://localhost:3000' });
85
+
86
+ client.DraftController.getTags('prefix').then(result => {
87
+ console.log('Found', result);
88
+ });
89
+ ```
90
+
91
+ The usage here is extremely simple, but outlines the simplicity of what is needed to make RPC requests.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/web-rpc",
3
- "version": "6.0.0-rc.7",
3
+ "version": "6.0.1",
4
4
  "description": "RPC support for a Web Application",
5
5
  "keywords": [
6
6
  "web",
@@ -26,9 +26,9 @@
26
26
  "directory": "module/web-rpc"
27
27
  },
28
28
  "dependencies": {
29
- "@travetto/config": "^6.0.0-rc.2",
30
- "@travetto/schema": "^6.0.0-rc.2",
31
- "@travetto/web": "^6.0.0-rc.6"
29
+ "@travetto/config": "^6.0.0",
30
+ "@travetto/schema": "^6.0.0",
31
+ "@travetto/web": "^6.0.1"
32
32
  },
33
33
  "travetto": {
34
34
  "displayName": "Web RPC Support"