@twin.org/api-rest-client 0.0.3-next.9 → 0.9.0
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 +8 -31
- 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 -21
- package/docs/changelog.md +773 -70
- package/docs/examples.md +64 -1
- package/docs/reference/classes/HealthRestClient.md +145 -0
- package/docs/reference/classes/InformationRestClient.md +80 -78
- package/docs/reference/index.md +1 -0
- package/locales/en.json +1 -7
- package/package.json +9 -9
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,190 +44,192 @@ Runtime name for the class.
|
|
|
44
44
|
|
|
45
45
|
## Methods
|
|
46
46
|
|
|
47
|
-
###
|
|
47
|
+
### getEndpointWithPrefix() {#getendpointwithprefix}
|
|
48
48
|
|
|
49
|
-
> **
|
|
49
|
+
> **getEndpointWithPrefix**(): `string`
|
|
50
50
|
|
|
51
|
-
|
|
51
|
+
Get the endpoint with the prefix for the namespace.
|
|
52
52
|
|
|
53
53
|
#### Returns
|
|
54
54
|
|
|
55
55
|
`string`
|
|
56
56
|
|
|
57
|
-
The
|
|
57
|
+
The endpoint with namespace prefix attached.
|
|
58
58
|
|
|
59
|
-
####
|
|
59
|
+
#### Inherited from
|
|
60
60
|
|
|
61
|
-
`
|
|
61
|
+
`BaseRestClient.getEndpointWithPrefix`
|
|
62
62
|
|
|
63
63
|
***
|
|
64
64
|
|
|
65
|
-
###
|
|
65
|
+
### fetch() {#fetch}
|
|
66
66
|
|
|
67
|
-
> **
|
|
67
|
+
> **fetch**\<`T`, `U`\>(`route`, `method`, `request?`): `Promise`\<`U`\>
|
|
68
68
|
|
|
69
|
-
|
|
69
|
+
Perform a request in json format.
|
|
70
70
|
|
|
71
|
-
####
|
|
71
|
+
#### Type Parameters
|
|
72
72
|
|
|
73
|
-
|
|
73
|
+
##### T
|
|
74
74
|
|
|
75
|
-
|
|
75
|
+
`T` *extends* `IHttpRequest`\<`any`\>
|
|
76
76
|
|
|
77
|
-
|
|
77
|
+
##### U
|
|
78
78
|
|
|
79
|
-
`
|
|
79
|
+
`U` *extends* `IHttpResponse`\<`any`\>
|
|
80
80
|
|
|
81
|
-
|
|
81
|
+
#### Parameters
|
|
82
82
|
|
|
83
|
-
|
|
83
|
+
##### route
|
|
84
84
|
|
|
85
|
-
|
|
85
|
+
`string`
|
|
86
86
|
|
|
87
|
-
|
|
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.
|
|
88
100
|
|
|
89
101
|
#### Returns
|
|
90
102
|
|
|
91
|
-
`Promise`\<`
|
|
103
|
+
`Promise`\<`U`\>
|
|
92
104
|
|
|
93
|
-
The
|
|
105
|
+
The response.
|
|
94
106
|
|
|
95
|
-
####
|
|
107
|
+
#### Inherited from
|
|
96
108
|
|
|
97
|
-
`
|
|
109
|
+
`BaseRestClient.fetch`
|
|
98
110
|
|
|
99
111
|
***
|
|
100
112
|
|
|
101
|
-
###
|
|
113
|
+
### className() {#classname}
|
|
102
114
|
|
|
103
|
-
> **
|
|
115
|
+
> **className**(): `string`
|
|
104
116
|
|
|
105
|
-
|
|
117
|
+
Returns the class name of the component.
|
|
106
118
|
|
|
107
119
|
#### Returns
|
|
108
120
|
|
|
109
|
-
`
|
|
121
|
+
`string`
|
|
110
122
|
|
|
111
|
-
The
|
|
123
|
+
The class name of the component.
|
|
112
124
|
|
|
113
125
|
#### Implementation of
|
|
114
126
|
|
|
115
|
-
`IInformationComponent.
|
|
127
|
+
`IInformationComponent.className`
|
|
116
128
|
|
|
117
129
|
***
|
|
118
130
|
|
|
119
|
-
###
|
|
131
|
+
### root() {#root}
|
|
120
132
|
|
|
121
|
-
> **
|
|
133
|
+
> **root**(): `Promise`\<`string`\>
|
|
122
134
|
|
|
123
|
-
Get the
|
|
135
|
+
Get the server root.
|
|
124
136
|
|
|
125
137
|
#### Returns
|
|
126
138
|
|
|
127
|
-
`Promise`\<`
|
|
139
|
+
`Promise`\<`string`\>
|
|
128
140
|
|
|
129
|
-
The
|
|
141
|
+
The root text page content.
|
|
130
142
|
|
|
131
143
|
#### Implementation of
|
|
132
144
|
|
|
133
|
-
`IInformationComponent.
|
|
145
|
+
`IInformationComponent.root`
|
|
134
146
|
|
|
135
147
|
***
|
|
136
148
|
|
|
137
|
-
###
|
|
149
|
+
### info() {#info}
|
|
138
150
|
|
|
139
|
-
> **
|
|
151
|
+
> **info**(): `Promise`\<`IServerInfo`\>
|
|
140
152
|
|
|
141
|
-
|
|
153
|
+
Get the server information.
|
|
142
154
|
|
|
143
155
|
#### Returns
|
|
144
156
|
|
|
145
|
-
`Promise`\<`
|
|
157
|
+
`Promise`\<`IServerInfo`\>
|
|
146
158
|
|
|
147
|
-
|
|
159
|
+
The service information.
|
|
148
160
|
|
|
149
161
|
#### Implementation of
|
|
150
162
|
|
|
151
|
-
`IInformationComponent.
|
|
163
|
+
`IInformationComponent.info`
|
|
152
164
|
|
|
153
165
|
***
|
|
154
166
|
|
|
155
|
-
###
|
|
167
|
+
### favicon() {#favicon}
|
|
156
168
|
|
|
157
|
-
> **
|
|
169
|
+
> **favicon**(): `Promise`\<`Uint8Array`\<`ArrayBufferLike`\> \| `undefined`\>
|
|
158
170
|
|
|
159
|
-
Get the
|
|
171
|
+
Get the favicon.
|
|
160
172
|
|
|
161
173
|
#### Returns
|
|
162
174
|
|
|
163
|
-
`Promise`\<`
|
|
175
|
+
`Promise`\<`Uint8Array`\<`ArrayBufferLike`\> \| `undefined`\>
|
|
164
176
|
|
|
165
|
-
The
|
|
177
|
+
The favicon.
|
|
166
178
|
|
|
167
179
|
#### Implementation of
|
|
168
180
|
|
|
169
|
-
`IInformationComponent.
|
|
181
|
+
`IInformationComponent.favicon`
|
|
170
182
|
|
|
171
183
|
***
|
|
172
184
|
|
|
173
|
-
###
|
|
174
|
-
|
|
175
|
-
> **setComponentHealth**(`name`, `status`, `details?`): `Promise`\<`void`\>
|
|
185
|
+
### spec() {#spec}
|
|
176
186
|
|
|
177
|
-
|
|
187
|
+
> **spec**(): `Promise`\<`unknown`\>
|
|
178
188
|
|
|
179
|
-
|
|
189
|
+
Get the OpenAPI spec.
|
|
180
190
|
|
|
181
|
-
|
|
191
|
+
#### Returns
|
|
182
192
|
|
|
183
|
-
`
|
|
193
|
+
`Promise`\<`unknown`\>
|
|
184
194
|
|
|
185
|
-
The
|
|
195
|
+
The OpenAPI spec.
|
|
186
196
|
|
|
187
|
-
|
|
197
|
+
#### Implementation of
|
|
188
198
|
|
|
189
|
-
`
|
|
199
|
+
`IInformationComponent.spec`
|
|
190
200
|
|
|
191
|
-
|
|
201
|
+
***
|
|
192
202
|
|
|
193
|
-
|
|
203
|
+
### livez() {#livez}
|
|
194
204
|
|
|
195
|
-
`
|
|
205
|
+
> **livez**(): `Promise`\<\{ `status`: `"alive"` \| `"dead"`; \}\>
|
|
196
206
|
|
|
197
|
-
|
|
207
|
+
Is the server live.
|
|
198
208
|
|
|
199
209
|
#### Returns
|
|
200
210
|
|
|
201
|
-
`Promise
|
|
211
|
+
`Promise`\<\{ `status`: `"alive"` \| `"dead"`; \}\>
|
|
202
212
|
|
|
203
|
-
|
|
213
|
+
The liveness status of the server.
|
|
204
214
|
|
|
205
215
|
#### Implementation of
|
|
206
216
|
|
|
207
|
-
`IInformationComponent.
|
|
217
|
+
`IInformationComponent.livez`
|
|
208
218
|
|
|
209
219
|
***
|
|
210
220
|
|
|
211
|
-
###
|
|
212
|
-
|
|
213
|
-
> **removeComponentHealth**(`name`): `Promise`\<`void`\>
|
|
214
|
-
|
|
215
|
-
Remove the status of a component.
|
|
221
|
+
### readyz() {#readyz}
|
|
216
222
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
##### name
|
|
220
|
-
|
|
221
|
-
`string`
|
|
223
|
+
> **readyz**(): `Promise`\<\{ `status`: `"ready"` \| `"not ready"`; \}\>
|
|
222
224
|
|
|
223
|
-
|
|
225
|
+
Is the server ready.
|
|
224
226
|
|
|
225
227
|
#### Returns
|
|
226
228
|
|
|
227
|
-
`Promise
|
|
229
|
+
`Promise`\<\{ `status`: `"ready"` \| `"not ready"`; \}\>
|
|
228
230
|
|
|
229
|
-
|
|
231
|
+
The readiness status of the server.
|
|
230
232
|
|
|
231
233
|
#### Implementation of
|
|
232
234
|
|
|
233
|
-
`IInformationComponent.
|
|
235
|
+
`IInformationComponent.readyz`
|
package/docs/reference/index.md
CHANGED
package/locales/en.json
CHANGED
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twin.org/api-rest-client",
|
|
3
|
-
"version": "0.0
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.9.0",
|
|
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,11 +14,11 @@
|
|
|
14
14
|
"node": ">=20.0.0"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@twin.org/api-core": "0.0
|
|
18
|
-
"@twin.org/api-models": "0.0
|
|
19
|
-
"@twin.org/core": "
|
|
20
|
-
"@twin.org/nameof": "
|
|
21
|
-
"@twin.org/web": "
|
|
17
|
+
"@twin.org/api-core": "^0.9.0",
|
|
18
|
+
"@twin.org/api-models": "^0.9.0",
|
|
19
|
+
"@twin.org/core": "^0.9.0",
|
|
20
|
+
"@twin.org/nameof": "^0.9.0",
|
|
21
|
+
"@twin.org/web": "^0.9.0"
|
|
22
22
|
},
|
|
23
23
|
"main": "./dist/es/index.js",
|
|
24
24
|
"types": "./dist/types/index.d.ts",
|
|
@@ -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
|
}
|