@twin.org/api-rest-client 0.0.3-next.4 → 0.0.3-next.40
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.
- package/README.md +1 -1
- package/dist/es/healthRestClient.js +35 -0
- package/dist/es/healthRestClient.js.map +1 -0
- package/dist/es/index.js +1 -0
- package/dist/es/index.js.map +1 -1
- package/dist/es/informationRestClient.js +10 -21
- package/dist/es/informationRestClient.js.map +1 -1
- package/dist/types/healthRestClient.d.ts +30 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/informationRestClient.d.ts +11 -16
- package/docs/changelog.md +607 -53
- package/docs/examples.md +64 -1
- package/docs/reference/classes/HealthRestClient.md +145 -0
- package/docs/reference/classes/InformationRestClient.md +84 -64
- package/docs/reference/index.md +1 -0
- package/package.json +6 -6
package/docs/examples.md
CHANGED
|
@@ -1 +1,64 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Rest Client Examples
|
|
2
|
+
|
|
3
|
+
Use these snippets to call health, metadata, and specification endpoints from operational tools and integration tests.
|
|
4
|
+
|
|
5
|
+
## InformationRestClient
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
import { InformationRestClient } from '@twin.org/api-rest-client';
|
|
9
|
+
|
|
10
|
+
const client = new InformationRestClient({
|
|
11
|
+
endpoint: 'https://api.example.org',
|
|
12
|
+
pathPrefix: 'v1'
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
console.log(client.className()); // InformationRestClient
|
|
16
|
+
|
|
17
|
+
const root = await client.root();
|
|
18
|
+
const info = await client.info();
|
|
19
|
+
const icon = await client.favicon();
|
|
20
|
+
|
|
21
|
+
console.log(root); // twin-api - 1.2.0
|
|
22
|
+
console.log(info.version); // 1.2.0
|
|
23
|
+
console.log((icon?.byteLength ?? 0) > 0); // true
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
```typescript
|
|
27
|
+
import { InformationRestClient } from '@twin.org/api-rest-client';
|
|
28
|
+
|
|
29
|
+
const client = new InformationRestClient({
|
|
30
|
+
endpoint: 'https://api.example.org',
|
|
31
|
+
pathPrefix: 'v1'
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const openApi = await client.spec();
|
|
35
|
+
const live = await client.livez();
|
|
36
|
+
const health = await client.health();
|
|
37
|
+
|
|
38
|
+
console.log(typeof openApi); // object
|
|
39
|
+
console.log(live); // true
|
|
40
|
+
console.log(health.status); // ok
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
```typescript
|
|
44
|
+
import { InformationRestClient } from '@twin.org/api-rest-client';
|
|
45
|
+
|
|
46
|
+
const client = new InformationRestClient({
|
|
47
|
+
endpoint: 'https://api.example.org',
|
|
48
|
+
pathPrefix: 'v1'
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
try {
|
|
52
|
+
await client.setComponentHealth('database', 'ok');
|
|
53
|
+
} catch (err) {
|
|
54
|
+
const errorName = err instanceof Error ? err.name : 'Error';
|
|
55
|
+
console.log(errorName); // NotSupportedError
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
try {
|
|
59
|
+
await client.removeComponentHealth('database');
|
|
60
|
+
} catch (err) {
|
|
61
|
+
const errorName = err instanceof Error ? err.name : 'Error';
|
|
62
|
+
console.log(errorName); // NotSupportedError
|
|
63
|
+
}
|
|
64
|
+
```
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
# Class: HealthRestClient
|
|
2
|
+
|
|
3
|
+
The client to connect to the health service.
|
|
4
|
+
|
|
5
|
+
## Extends
|
|
6
|
+
|
|
7
|
+
- `BaseRestClient`
|
|
8
|
+
|
|
9
|
+
## Implements
|
|
10
|
+
|
|
11
|
+
- `IHealthComponent`
|
|
12
|
+
|
|
13
|
+
## Constructors
|
|
14
|
+
|
|
15
|
+
### Constructor
|
|
16
|
+
|
|
17
|
+
> **new HealthRestClient**(`config`): `HealthRestClient`
|
|
18
|
+
|
|
19
|
+
Create a new instance of HealthRestClient.
|
|
20
|
+
|
|
21
|
+
#### Parameters
|
|
22
|
+
|
|
23
|
+
##### config
|
|
24
|
+
|
|
25
|
+
`IBaseRestClientConfig`
|
|
26
|
+
|
|
27
|
+
The configuration for the client.
|
|
28
|
+
|
|
29
|
+
#### Returns
|
|
30
|
+
|
|
31
|
+
`HealthRestClient`
|
|
32
|
+
|
|
33
|
+
#### Overrides
|
|
34
|
+
|
|
35
|
+
`BaseRestClient.constructor`
|
|
36
|
+
|
|
37
|
+
## Properties
|
|
38
|
+
|
|
39
|
+
### CLASS\_NAME {#class_name}
|
|
40
|
+
|
|
41
|
+
> `readonly` `static` **CLASS\_NAME**: `string`
|
|
42
|
+
|
|
43
|
+
Runtime name for the class.
|
|
44
|
+
|
|
45
|
+
## Methods
|
|
46
|
+
|
|
47
|
+
### getEndpointWithPrefix() {#getendpointwithprefix}
|
|
48
|
+
|
|
49
|
+
> **getEndpointWithPrefix**(): `string`
|
|
50
|
+
|
|
51
|
+
Get the endpoint with the prefix for the namespace.
|
|
52
|
+
|
|
53
|
+
#### Returns
|
|
54
|
+
|
|
55
|
+
`string`
|
|
56
|
+
|
|
57
|
+
The endpoint with namespace prefix attached.
|
|
58
|
+
|
|
59
|
+
#### Inherited from
|
|
60
|
+
|
|
61
|
+
`BaseRestClient.getEndpointWithPrefix`
|
|
62
|
+
|
|
63
|
+
***
|
|
64
|
+
|
|
65
|
+
### fetch() {#fetch}
|
|
66
|
+
|
|
67
|
+
> **fetch**\<`T`, `U`\>(`route`, `method`, `request?`): `Promise`\<`U`\>
|
|
68
|
+
|
|
69
|
+
Perform a request in json format.
|
|
70
|
+
|
|
71
|
+
#### Type Parameters
|
|
72
|
+
|
|
73
|
+
##### T
|
|
74
|
+
|
|
75
|
+
`T` *extends* `IHttpRequest`\<`any`\>
|
|
76
|
+
|
|
77
|
+
##### U
|
|
78
|
+
|
|
79
|
+
`U` *extends* `IHttpResponse`\<`any`\>
|
|
80
|
+
|
|
81
|
+
#### Parameters
|
|
82
|
+
|
|
83
|
+
##### route
|
|
84
|
+
|
|
85
|
+
`string`
|
|
86
|
+
|
|
87
|
+
The route of the request.
|
|
88
|
+
|
|
89
|
+
##### method
|
|
90
|
+
|
|
91
|
+
`HttpMethod`
|
|
92
|
+
|
|
93
|
+
The http method.
|
|
94
|
+
|
|
95
|
+
##### request?
|
|
96
|
+
|
|
97
|
+
`T`
|
|
98
|
+
|
|
99
|
+
Request to send to the endpoint.
|
|
100
|
+
|
|
101
|
+
#### Returns
|
|
102
|
+
|
|
103
|
+
`Promise`\<`U`\>
|
|
104
|
+
|
|
105
|
+
The response.
|
|
106
|
+
|
|
107
|
+
#### Inherited from
|
|
108
|
+
|
|
109
|
+
`BaseRestClient.fetch`
|
|
110
|
+
|
|
111
|
+
***
|
|
112
|
+
|
|
113
|
+
### className() {#classname}
|
|
114
|
+
|
|
115
|
+
> **className**(): `string`
|
|
116
|
+
|
|
117
|
+
Returns the class name of the component.
|
|
118
|
+
|
|
119
|
+
#### Returns
|
|
120
|
+
|
|
121
|
+
`string`
|
|
122
|
+
|
|
123
|
+
The class name of the component.
|
|
124
|
+
|
|
125
|
+
#### Implementation of
|
|
126
|
+
|
|
127
|
+
`IHealthComponent.className`
|
|
128
|
+
|
|
129
|
+
***
|
|
130
|
+
|
|
131
|
+
### healthStatus() {#healthstatus}
|
|
132
|
+
|
|
133
|
+
> **healthStatus**(): `Promise`\<\{ `status`: `HealthStatus`; `components`: `IHealth`[]; \}\>
|
|
134
|
+
|
|
135
|
+
Get the server health.
|
|
136
|
+
|
|
137
|
+
#### Returns
|
|
138
|
+
|
|
139
|
+
`Promise`\<\{ `status`: `HealthStatus`; `components`: `IHealth`[]; \}\>
|
|
140
|
+
|
|
141
|
+
The service health.
|
|
142
|
+
|
|
143
|
+
#### Implementation of
|
|
144
|
+
|
|
145
|
+
`IHealthComponent.healthStatus`
|
|
@@ -36,7 +36,7 @@ The configuration for the client.
|
|
|
36
36
|
|
|
37
37
|
## Properties
|
|
38
38
|
|
|
39
|
-
### CLASS\_NAME
|
|
39
|
+
### CLASS\_NAME {#class_name}
|
|
40
40
|
|
|
41
41
|
> `readonly` `static` **CLASS\_NAME**: `string`
|
|
42
42
|
|
|
@@ -44,7 +44,73 @@ Runtime name for the class.
|
|
|
44
44
|
|
|
45
45
|
## Methods
|
|
46
46
|
|
|
47
|
-
###
|
|
47
|
+
### getEndpointWithPrefix() {#getendpointwithprefix}
|
|
48
|
+
|
|
49
|
+
> **getEndpointWithPrefix**(): `string`
|
|
50
|
+
|
|
51
|
+
Get the endpoint with the prefix for the namespace.
|
|
52
|
+
|
|
53
|
+
#### Returns
|
|
54
|
+
|
|
55
|
+
`string`
|
|
56
|
+
|
|
57
|
+
The endpoint with namespace prefix attached.
|
|
58
|
+
|
|
59
|
+
#### Inherited from
|
|
60
|
+
|
|
61
|
+
`BaseRestClient.getEndpointWithPrefix`
|
|
62
|
+
|
|
63
|
+
***
|
|
64
|
+
|
|
65
|
+
### fetch() {#fetch}
|
|
66
|
+
|
|
67
|
+
> **fetch**\<`T`, `U`\>(`route`, `method`, `request?`): `Promise`\<`U`\>
|
|
68
|
+
|
|
69
|
+
Perform a request in json format.
|
|
70
|
+
|
|
71
|
+
#### Type Parameters
|
|
72
|
+
|
|
73
|
+
##### T
|
|
74
|
+
|
|
75
|
+
`T` *extends* `IHttpRequest`\<`any`\>
|
|
76
|
+
|
|
77
|
+
##### U
|
|
78
|
+
|
|
79
|
+
`U` *extends* `IHttpResponse`\<`any`\>
|
|
80
|
+
|
|
81
|
+
#### Parameters
|
|
82
|
+
|
|
83
|
+
##### route
|
|
84
|
+
|
|
85
|
+
`string`
|
|
86
|
+
|
|
87
|
+
The route of the request.
|
|
88
|
+
|
|
89
|
+
##### method
|
|
90
|
+
|
|
91
|
+
`HttpMethod`
|
|
92
|
+
|
|
93
|
+
The http method.
|
|
94
|
+
|
|
95
|
+
##### request?
|
|
96
|
+
|
|
97
|
+
`T`
|
|
98
|
+
|
|
99
|
+
Request to send to the endpoint.
|
|
100
|
+
|
|
101
|
+
#### Returns
|
|
102
|
+
|
|
103
|
+
`Promise`\<`U`\>
|
|
104
|
+
|
|
105
|
+
The response.
|
|
106
|
+
|
|
107
|
+
#### Inherited from
|
|
108
|
+
|
|
109
|
+
`BaseRestClient.fetch`
|
|
110
|
+
|
|
111
|
+
***
|
|
112
|
+
|
|
113
|
+
### className() {#classname}
|
|
48
114
|
|
|
49
115
|
> **className**(): `string`
|
|
50
116
|
|
|
@@ -62,7 +128,7 @@ The class name of the component.
|
|
|
62
128
|
|
|
63
129
|
***
|
|
64
130
|
|
|
65
|
-
### root()
|
|
131
|
+
### root() {#root}
|
|
66
132
|
|
|
67
133
|
> **root**(): `Promise`\<`string`\>
|
|
68
134
|
|
|
@@ -80,7 +146,7 @@ The root root.
|
|
|
80
146
|
|
|
81
147
|
***
|
|
82
148
|
|
|
83
|
-
### info()
|
|
149
|
+
### info() {#info}
|
|
84
150
|
|
|
85
151
|
> **info**(): `Promise`\<`IServerInfo`\>
|
|
86
152
|
|
|
@@ -98,7 +164,7 @@ The service information.
|
|
|
98
164
|
|
|
99
165
|
***
|
|
100
166
|
|
|
101
|
-
### favicon()
|
|
167
|
+
### favicon() {#favicon}
|
|
102
168
|
|
|
103
169
|
> **favicon**(): `Promise`\<`Uint8Array`\<`ArrayBufferLike`\> \| `undefined`\>
|
|
104
170
|
|
|
@@ -116,7 +182,7 @@ The favicon.
|
|
|
116
182
|
|
|
117
183
|
***
|
|
118
184
|
|
|
119
|
-
### spec()
|
|
185
|
+
### spec() {#spec}
|
|
120
186
|
|
|
121
187
|
> **spec**(): `Promise`\<`unknown`\>
|
|
122
188
|
|
|
@@ -134,82 +200,36 @@ The OpenAPI spec.
|
|
|
134
200
|
|
|
135
201
|
***
|
|
136
202
|
|
|
137
|
-
###
|
|
203
|
+
### livez() {#livez}
|
|
138
204
|
|
|
139
|
-
> **
|
|
205
|
+
> **livez**(): `Promise`\<\{ `status`: `"alive"` \| `"dead"`; \}\>
|
|
140
206
|
|
|
141
|
-
|
|
207
|
+
Is the server live.
|
|
142
208
|
|
|
143
209
|
#### Returns
|
|
144
210
|
|
|
145
|
-
`Promise
|
|
211
|
+
`Promise`\<\{ `status`: `"alive"` \| `"dead"`; \}\>
|
|
146
212
|
|
|
147
|
-
|
|
213
|
+
True if the server is live.
|
|
148
214
|
|
|
149
215
|
#### Implementation of
|
|
150
216
|
|
|
151
|
-
`IInformationComponent.
|
|
217
|
+
`IInformationComponent.livez`
|
|
152
218
|
|
|
153
219
|
***
|
|
154
220
|
|
|
155
|
-
###
|
|
156
|
-
|
|
157
|
-
> **setComponentHealth**(`name`, `status`, `details?`): `Promise`\<`void`\>
|
|
158
|
-
|
|
159
|
-
Set the status of a component.
|
|
160
|
-
|
|
161
|
-
#### Parameters
|
|
162
|
-
|
|
163
|
-
##### name
|
|
164
|
-
|
|
165
|
-
`string`
|
|
166
|
-
|
|
167
|
-
The component name.
|
|
168
|
-
|
|
169
|
-
##### status
|
|
170
|
-
|
|
171
|
-
`HealthStatus`
|
|
172
|
-
|
|
173
|
-
The status of the component.
|
|
174
|
-
|
|
175
|
-
##### details?
|
|
176
|
-
|
|
177
|
-
`string`
|
|
221
|
+
### readyz() {#readyz}
|
|
178
222
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
#### Returns
|
|
182
|
-
|
|
183
|
-
`Promise`\<`void`\>
|
|
184
|
-
|
|
185
|
-
Nothing.
|
|
186
|
-
|
|
187
|
-
#### Implementation of
|
|
188
|
-
|
|
189
|
-
`IInformationComponent.setComponentHealth`
|
|
190
|
-
|
|
191
|
-
***
|
|
192
|
-
|
|
193
|
-
### removeComponentHealth()
|
|
194
|
-
|
|
195
|
-
> **removeComponentHealth**(`name`): `Promise`\<`void`\>
|
|
196
|
-
|
|
197
|
-
Remove the status of a component.
|
|
198
|
-
|
|
199
|
-
#### Parameters
|
|
200
|
-
|
|
201
|
-
##### name
|
|
202
|
-
|
|
203
|
-
`string`
|
|
223
|
+
> **readyz**(): `Promise`\<\{ `status`: `"ready"` \| `"not ready"`; \}\>
|
|
204
224
|
|
|
205
|
-
|
|
225
|
+
Is the server ready.
|
|
206
226
|
|
|
207
227
|
#### Returns
|
|
208
228
|
|
|
209
|
-
`Promise
|
|
229
|
+
`Promise`\<\{ `status`: `"ready"` \| `"not ready"`; \}\>
|
|
210
230
|
|
|
211
|
-
|
|
231
|
+
True if the server is ready.
|
|
212
232
|
|
|
213
233
|
#### Implementation of
|
|
214
234
|
|
|
215
|
-
`IInformationComponent.
|
|
235
|
+
`IInformationComponent.readyz`
|
package/docs/reference/index.md
CHANGED
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twin.org/api-rest-client",
|
|
3
|
-
"version": "0.0.3-next.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.0.3-next.40",
|
|
4
|
+
"description": "REST client implementation for consuming information and hosting endpoints.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
|
-
"url": "git+https://github.com/
|
|
7
|
+
"url": "git+https://github.com/iotaledger/twin-api.git",
|
|
8
8
|
"directory": "packages/api-rest-client"
|
|
9
9
|
},
|
|
10
10
|
"author": "martyn.janes@iota.org",
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
"node": ">=20.0.0"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@twin.org/api-core": "0.0.3-next.
|
|
18
|
-
"@twin.org/api-models": "0.0.3-next.
|
|
17
|
+
"@twin.org/api-core": "0.0.3-next.40",
|
|
18
|
+
"@twin.org/api-models": "0.0.3-next.40",
|
|
19
19
|
"@twin.org/core": "next",
|
|
20
20
|
"@twin.org/nameof": "next",
|
|
21
21
|
"@twin.org/web": "next"
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"api"
|
|
45
45
|
],
|
|
46
46
|
"bugs": {
|
|
47
|
-
"url": "git+https://github.com/
|
|
47
|
+
"url": "git+https://github.com/iotaledger/twin-api/issues"
|
|
48
48
|
},
|
|
49
49
|
"homepage": "https://twindev.org"
|
|
50
50
|
}
|