@mittwald/api-client 3.0.2 → 3.0.4
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 +93 -6
- package/dist/cjs/generated/v2/client-react.d.ts +1916 -0
- package/dist/cjs/generated/v2/client-react.js +332 -0
- package/dist/cjs/generated/v2/client.js +24 -1
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/index.js +2 -2
- package/dist/cjs/react.d.ts +1 -0
- package/dist/cjs/react.js +5 -0
- package/dist/cjs/{v2.d.ts → v2/default.d.ts} +2 -2
- package/dist/cjs/{v2.js → v2/default.js} +5 -2
- package/dist/cjs/v2/react.d.ts +3 -0
- package/dist/cjs/v2/react.js +7 -0
- package/dist/esm/generated/v2/client-react.d.ts +1916 -0
- package/dist/esm/generated/v2/client-react.js +334 -0
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/react.d.ts +1 -0
- package/dist/esm/react.js +1 -0
- package/dist/esm/{v2.d.ts → v2/default.d.ts} +2 -2
- package/dist/esm/{v2.js → v2/default.js} +2 -2
- package/dist/esm/v2/react.d.ts +3 -0
- package/dist/esm/v2/react.js +3 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +21 -2
package/README.md
CHANGED
|
@@ -10,6 +10,27 @@ Copyright (c) 2023 Mittwald CM Service GmbH & Co. KG and contributors
|
|
|
10
10
|
This project (and all NPM packages) therein is licensed under the MIT License;
|
|
11
11
|
see the [LICENSE](../../LICENSE) file for details.
|
|
12
12
|
|
|
13
|
+
## Table of contents
|
|
14
|
+
|
|
15
|
+
- [Installing](#installing)
|
|
16
|
+
- [Usage](#usage)
|
|
17
|
+
- [Setting request parameters](#setting-request-parameters)
|
|
18
|
+
- [Path parameters](#path-parameters)
|
|
19
|
+
- [Headers, query parameters and request body](#headers-query-parameters-and-request-body)
|
|
20
|
+
- [Example](#example)
|
|
21
|
+
- [Usage in React](#usage-in-react)
|
|
22
|
+
- [Installation](#installation)
|
|
23
|
+
- [Setup](#setup)
|
|
24
|
+
- [Usage](#usage-1)
|
|
25
|
+
- [Example](#example-1)
|
|
26
|
+
- [API documentation](#api-documentation)
|
|
27
|
+
- [Accessing the underlying Axios instance](#accessing-the-underlying-axios-instance)
|
|
28
|
+
- [Adding custom HTTP headers](#adding-custom-http-headers)
|
|
29
|
+
- [Intercepting requests or responses](#intercepting-requests-or-responses)
|
|
30
|
+
- [Usage with TypeScript](#usage-with-typescript)
|
|
31
|
+
- [Importing types](#importing-types)
|
|
32
|
+
- [Migrating from package version V2 to V3](#migrating-from-package-version-v2-to-v3)
|
|
33
|
+
|
|
13
34
|
## Installing
|
|
14
35
|
|
|
15
36
|
You can install this package from the regular NPM registry:
|
|
@@ -62,7 +83,7 @@ object.
|
|
|
62
83
|
|
|
63
84
|
```javascript
|
|
64
85
|
// Setting the projectId path parameters
|
|
65
|
-
const project = await mittwaldApi.project.
|
|
86
|
+
const project = await mittwaldApi.project.getProject({
|
|
66
87
|
projectId: "p-xxxxx",
|
|
67
88
|
});
|
|
68
89
|
```
|
|
@@ -80,7 +101,6 @@ When using TypeScript all parameter schemas are reflected by the request type,
|
|
|
80
101
|
so you will get compile errors, when a request does not match the schema.
|
|
81
102
|
|
|
82
103
|
```javascript
|
|
83
|
-
// Setting the projectId path parameters
|
|
84
104
|
const response = await mittwaldApi.category.operation({
|
|
85
105
|
// path parameters
|
|
86
106
|
pathParameter1: "param1",
|
|
@@ -91,8 +111,8 @@ const response = await mittwaldApi.category.operation({
|
|
|
91
111
|
},
|
|
92
112
|
// query parameters
|
|
93
113
|
queryParameters: {
|
|
94
|
-
|
|
95
|
-
|
|
114
|
+
queryParameter1: "queryParam1",
|
|
115
|
+
queryParameter2: "queryParam2",
|
|
96
116
|
},
|
|
97
117
|
// JSON object in request body
|
|
98
118
|
data: {
|
|
@@ -112,6 +132,73 @@ const mittwaldApi = MittwaldAPIClient.newWithToken("your-access-token");
|
|
|
112
132
|
const projects = await mittwaldApi.project.listProjects();
|
|
113
133
|
```
|
|
114
134
|
|
|
135
|
+
## Usage in React
|
|
136
|
+
|
|
137
|
+
This package also provides a client aligned to be used in React components. It
|
|
138
|
+
uses
|
|
139
|
+
[`@mittwald/react-use-promise`](https://www.npmjs.com/package/@mittwald/react-use-promise)
|
|
140
|
+
to encapsulate the asynchronous API functions into AsyncResources. More details
|
|
141
|
+
about how to use AsyncResources see the
|
|
142
|
+
[package documentation](https://www.npmjs.com/package/@mittwald/react-use-promise#terminology).
|
|
143
|
+
|
|
144
|
+
### Installation
|
|
145
|
+
|
|
146
|
+
To use the React client you have to install the additional
|
|
147
|
+
`@mittwald/react-use-promise` package:
|
|
148
|
+
|
|
149
|
+
```shell
|
|
150
|
+
yarn add @mittwald/react-use-promise
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### Setup
|
|
154
|
+
|
|
155
|
+
To create a React client instance, you first need an instance of the regular
|
|
156
|
+
(promise-based) client. Then you can use the `.fromBaseClient(api)` method to
|
|
157
|
+
build the React client.
|
|
158
|
+
|
|
159
|
+
```javascript
|
|
160
|
+
const api = MittwaldAPIV2Client.newUnauthenticated();
|
|
161
|
+
const apiReact = MittwaldAPIV2ClientReact.fromBaseClient(api);
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### Usage
|
|
165
|
+
|
|
166
|
+
The React client has an equivalent for every GET method of the regular client.
|
|
167
|
+
The methods returning an AsyncResource that can be used to get the API
|
|
168
|
+
responses.
|
|
169
|
+
|
|
170
|
+
If the response is not OK (status 200), an `ApiClientError` will be thrown.
|
|
171
|
+
Errors can be handled by using error-boundaries. See the
|
|
172
|
+
[error handling section](https://www.npmjs.com/package/@mittwald/react-use-promise#error-handling)
|
|
173
|
+
for more details.
|
|
174
|
+
|
|
175
|
+
### Example
|
|
176
|
+
|
|
177
|
+
```javascript jsx
|
|
178
|
+
import { MittwaldAPIV2Client } from "@mittwald/api-client";
|
|
179
|
+
import { MittwaldAPIV2ClientReact } from "@mittwald/api-client/react";
|
|
180
|
+
|
|
181
|
+
const api = MittwaldAPIV2Client.newUnauthenticated();
|
|
182
|
+
const apiReact = MittwaldAPIV2ClientReact.fromBaseClient(api);
|
|
183
|
+
|
|
184
|
+
const ProjectsList = () => {
|
|
185
|
+
// apiReact.project.listProjects() returns an AsyncResource that can be "watched"
|
|
186
|
+
const projects = apiReact.project.listProjects().watch({
|
|
187
|
+
autoRefresh: {
|
|
188
|
+
seconds: 30,
|
|
189
|
+
},
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
return (
|
|
193
|
+
<ul>
|
|
194
|
+
{projects.map((p) => (
|
|
195
|
+
<li key={p.id}>{p.description}</li>
|
|
196
|
+
))}
|
|
197
|
+
</ul>
|
|
198
|
+
);
|
|
199
|
+
};
|
|
200
|
+
```
|
|
201
|
+
|
|
115
202
|
## API documentation
|
|
116
203
|
|
|
117
204
|
The API documentation can be found at
|
|
@@ -168,14 +255,14 @@ directly in the root level of the request object.
|
|
|
168
255
|
|
|
169
256
|
```javascript
|
|
170
257
|
// V2
|
|
171
|
-
mittwaldApi.project.
|
|
258
|
+
mittwaldApi.project.getProject({
|
|
172
259
|
pathParameters: {
|
|
173
260
|
projectId: "p-xxxxx",
|
|
174
261
|
},
|
|
175
262
|
});
|
|
176
263
|
|
|
177
264
|
// V3
|
|
178
|
-
mittwaldApi.project.
|
|
265
|
+
mittwaldApi.project.getProject({
|
|
179
266
|
projectId: "p-xxxxx",
|
|
180
267
|
});
|
|
181
268
|
```
|