@twin.org/api-rest-client 0.0.3-next.20 → 0.0.3-next.21
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/docs/changelog.md +16 -1
- package/docs/examples.md +64 -1
- package/docs/reference/classes/InformationRestClient.md +66 -0
- package/package.json +4 -4
package/README.md
CHANGED
package/docs/changelog.md
CHANGED
|
@@ -1,4 +1,19 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [0.0.3-next.21](https://github.com/twinfoundation/api/compare/api-rest-client-v0.0.3-next.20...api-rest-client-v0.0.3-next.21) (2026-03-11)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Miscellaneous Chores
|
|
7
|
+
|
|
8
|
+
* **api-rest-client:** Synchronize repo versions
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Dependencies
|
|
12
|
+
|
|
13
|
+
* The following workspace dependencies were updated
|
|
14
|
+
* dependencies
|
|
15
|
+
* @twin.org/api-core bumped from 0.0.3-next.20 to 0.0.3-next.21
|
|
16
|
+
* @twin.org/api-models bumped from 0.0.3-next.20 to 0.0.3-next.21
|
|
2
17
|
|
|
3
18
|
## [0.0.3-next.20](https://github.com/twinfoundation/api/compare/api-rest-client-v0.0.3-next.19...api-rest-client-v0.0.3-next.20) (2026-02-09)
|
|
4
19
|
|
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
|
+
```
|
|
@@ -44,6 +44,72 @@ Runtime name for the class.
|
|
|
44
44
|
|
|
45
45
|
## Methods
|
|
46
46
|
|
|
47
|
+
### 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()
|
|
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
|
+
|
|
47
113
|
### className()
|
|
48
114
|
|
|
49
115
|
> **className**(): `string`
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twin.org/api-rest-client",
|
|
3
|
-
"version": "0.0.3-next.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.0.3-next.21",
|
|
4
|
+
"description": "REST client implementation for consuming information and hosting endpoints.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/twinfoundation/api.git",
|
|
@@ -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.21",
|
|
18
|
+
"@twin.org/api-models": "0.0.3-next.21",
|
|
19
19
|
"@twin.org/core": "next",
|
|
20
20
|
"@twin.org/nameof": "next",
|
|
21
21
|
"@twin.org/web": "next"
|