api-def 0.12.0-alpha.31 → 0.12.0-alpha.33
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 +14 -11
- package/bin/index.js +114 -114
- package/cjs/Api.js +1 -1
- package/cjs/ApiTypes.d.ts +1 -1
- package/cjs/Endpoint.d.ts +1 -1
- package/cjs/Endpoint.js +4 -4
- package/cjs/Requester.js +1 -1
- package/esm/Api.js +1 -1
- package/esm/ApiTypes.d.ts +1 -1
- package/esm/Endpoint.d.ts +1 -1
- package/esm/Endpoint.js +4 -4
- package/esm/Requester.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,30 +4,33 @@ Typed APIs with middleware support
|
|
|
4
4
|
|
|
5
5
|
API def provides a unified way to type your endpoints allowing for compile time checking of query, body, response and even url parameters
|
|
6
6
|
|
|
7
|
-
```
|
|
7
|
+
```bash
|
|
8
|
+
npm i api-def
|
|
9
|
+
```
|
|
8
10
|
|
|
9
11
|
- [Documentation](https://censkh.github.io/api-def/)
|
|
10
12
|
|
|
11
13
|
```typescript
|
|
12
|
-
import {Api} from "api-def";
|
|
14
|
+
import { Api } from "api-def";
|
|
13
15
|
|
|
14
16
|
const api = new Api({
|
|
15
17
|
baseUrl: "https://my-api/",
|
|
16
18
|
name: "My API",
|
|
17
19
|
});
|
|
18
20
|
|
|
19
|
-
const fetchData = api
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
21
|
+
const fetchData = api
|
|
22
|
+
.endpoint()
|
|
23
|
+
.queryOf<{ includeAwesome: boolean }>()
|
|
24
|
+
.responseOf<{ data: { awesome: boolean } }>()
|
|
25
|
+
.build({
|
|
26
|
+
id: "fetch_data",
|
|
27
|
+
method: "get",
|
|
28
|
+
path: "/data",
|
|
29
|
+
});
|
|
27
30
|
|
|
28
31
|
// calls GET https://my-api/data?includeAwesome=true
|
|
29
32
|
const res = await fetchData.submit({
|
|
30
|
-
query: {includeAwesome: true}
|
|
33
|
+
query: { includeAwesome: true },
|
|
31
34
|
});
|
|
32
35
|
|
|
33
36
|
console.log(res.data); // { data: { awesome: true } }
|