@labeg/tfetch 0.8.0 → 0.8.1

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.
Files changed (2) hide show
  1. package/README.md +140 -6
  2. package/package.json +5 -5
package/README.md CHANGED
@@ -1,10 +1,14 @@
1
- Typescript Serializable Fetch
2
- =====
1
+ # Typescript Serializable Fetch
2
+
3
+ ![npm version](https://img.shields.io/npm/v/@labeg/tfetch.svg)
4
+ ![npm downloads](https://img.shields.io/npm/dm/@labeg/tfetch.svg)
5
+ ![GitHub](https://img.shields.io/github/license/LabEG/ts-fetch.svg)
6
+ ![build status](https://github.com/LabEG/ts-fetch/workflows/Test%20Pull%20Request/badge.svg)
7
+ [![CodeQL](https://github.com/LabEG/ts-fetch/workflows/CodeQL%20Advanced/badge.svg)](https://github.com/LabEG/ts-fetch/security/code-scanning)
3
8
 
4
9
  A small library for sending serialized data and receiving deserialized data with strict data type checking. This library is built on top of the Fetch API and provides additional features like caching, error handling, and support for serializable classes.
5
10
 
6
- Installation
7
- ------
11
+ ## Installation
8
12
 
9
13
  You can use the following command to install this package:
10
14
 
@@ -12,8 +16,7 @@ You can use the following command to install this package:
12
16
  npm install @labeg/tfetch
13
17
  ```
14
18
 
15
- Usage
16
- ------
19
+ ## Usage
17
20
 
18
21
  ### Basic Usage
19
22
 
@@ -49,6 +52,137 @@ const fetchClass = async () => {
49
52
  fetchClass();
50
53
  ```
51
54
 
55
+ ### POST Request with Body
56
+
57
+ ```typescript
58
+ import { tfetch } from "@labeg/tfetch";
59
+
60
+ const createUser = async () => {
61
+ const result = await tfetch({
62
+ method: "POST",
63
+ url: "https://example.com/api/users",
64
+ body: {
65
+ name: "John Doe",
66
+ email: "john@example.com"
67
+ },
68
+ returnType: Object
69
+ });
70
+ console.log(result);
71
+ };
72
+
73
+ createUser();
74
+ ```
75
+
76
+ ### Custom Headers
77
+
78
+ ```typescript
79
+ import { tfetch } from "@labeg/tfetch";
80
+
81
+ const fetchWithHeaders = async () => {
82
+ const result = await tfetch({
83
+ method: "GET",
84
+ url: "https://example.com/api/data",
85
+ headers: {
86
+ "Authorization": "Bearer your-token-here",
87
+ "X-Custom-Header": "custom-value"
88
+ },
89
+ returnType: Object
90
+ });
91
+ console.log(result);
92
+ };
93
+
94
+ fetchWithHeaders();
95
+ ```
96
+
97
+ ### All HTTP Methods
98
+
99
+ ```typescript
100
+ import { tfetch } from "@labeg/tfetch";
101
+
102
+ // GET request
103
+ const getData = async () => {
104
+ return await tfetch({
105
+ method: "GET",
106
+ url: "https://example.com/api/resource",
107
+ returnType: Object
108
+ });
109
+ };
110
+
111
+ // POST request
112
+ const postData = async () => {
113
+ return await tfetch({
114
+ method: "POST",
115
+ url: "https://example.com/api/resource",
116
+ body: { data: "value" },
117
+ returnType: Object
118
+ });
119
+ };
120
+
121
+ // PUT request
122
+ const updateData = async () => {
123
+ return await tfetch({
124
+ method: "PUT",
125
+ url: "https://example.com/api/resource/1",
126
+ body: { data: "updated value" }
127
+ });
128
+ };
129
+
130
+ // DELETE request
131
+ const deleteData = async () => {
132
+ return await tfetch({
133
+ method: "DELETE",
134
+ url: "https://example.com/api/resource/1"
135
+ });
136
+ };
137
+ ```
138
+
139
+ ### Advanced Fetch Options
140
+
141
+ You can pass any standard Fetch API options:
142
+
143
+ ```typescript
144
+ import { tfetch } from "@labeg/tfetch";
145
+
146
+ const advancedRequest = async () => {
147
+ const result = await tfetch({
148
+ method: "POST",
149
+ url: "https://example.com/api/data",
150
+ body: { key: "value" },
151
+ returnType: Object,
152
+ // Standard Fetch API options
153
+ cache: "no-cache",
154
+ credentials: "include",
155
+ mode: "cors",
156
+ redirect: "follow",
157
+ referrerPolicy: "no-referrer",
158
+ signal: AbortSignal.timeout(5000), // 5 second timeout
159
+ });
160
+ console.log(result);
161
+ };
162
+
163
+ advancedRequest();
164
+ ```
165
+
166
+ ### Working with FormData
167
+
168
+ ```typescript
169
+ import { tfetch } from "@labeg/tfetch";
170
+
171
+ const uploadFile = async (file: File) => {
172
+ const formData = new FormData();
173
+ formData.append("file", file);
174
+ formData.append("description", "My file");
175
+
176
+ const result = await tfetch({
177
+ method: "POST",
178
+ url: "https://example.com/api/upload",
179
+ body: formData,
180
+ returnType: Object
181
+ });
182
+ console.log(result);
183
+ };
184
+ ```
185
+
52
186
  ### CRUD Operations with `CrudHttpRepository`
53
187
 
54
188
  ```typescript
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@labeg/tfetch",
3
- "version": "0.8.0",
3
+ "version": "0.8.1",
4
4
  "author": "Eugene Labutin",
5
5
  "license": "MIT",
6
6
  "homepage": "https://github.com/LabEG/ts-fetch#readme",
@@ -35,17 +35,17 @@
35
35
  "ts-serializable": ">=3.0.0"
36
36
  },
37
37
  "devDependencies": {
38
- "@commitlint/cli": "^19.8.1",
39
- "@commitlint/config-conventional": "^19.8.1",
38
+ "@commitlint/cli": "^20.2.0",
39
+ "@commitlint/config-conventional": "^20.2.0",
40
40
  "@favware/cliff-jumper": "^6.0.0",
41
41
  "@labeg/code-style": "^6.5.0",
42
42
  "@swc-node/register": "^1.10.10",
43
43
  "@types/chai": "^5.2.2",
44
- "chai": "^5.2.1",
44
+ "chai": "^6.2.1",
45
45
  "fastify": "^5.4.0",
46
46
  "husky": "^9.1.7",
47
47
  "lint-staged": "^16.1.2",
48
- "npm-check-updates": "^18.0.1",
48
+ "npm-check-updates": "^19.2.0",
49
49
  "rimraf": "^6.0.1",
50
50
  "ts-serializable": "^4.2.1",
51
51
  "typescript": "^5.8.3"