@labeg/tfetch 0.8.1 → 0.8.2

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 +21 -7
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -37,19 +37,33 @@ fetchNumber();
37
37
 
38
38
  ### Working with Serializable Classes
39
39
 
40
+ To use automatic deserialization with classes, you need to use the [ts-serializable](https://github.com/LabEG/Serializable) library to define your models:
41
+
40
42
  ```typescript
41
43
  import { tfetch } from "@labeg/tfetch";
42
- import { TestClass } from "./fixtures/TestClass";
44
+ import { Serializable, jsonProperty } from "ts-serializable";
45
+
46
+ class User extends Serializable {
47
+ @jsonProperty(String)
48
+ public name: string = "";
49
+
50
+ @jsonProperty(String)
51
+ public email: string = "";
52
+
53
+ @jsonProperty(Number)
54
+ public age: number = 0;
55
+ }
43
56
 
44
- const fetchClass = async () => {
45
- const result: TestClass = await tfetch({
46
- url: "https://example.com/class",
47
- returnType: TestClass
57
+ const fetchUser = async () => {
58
+ const result: User = await tfetch({
59
+ url: "https://example.com/api/user/1",
60
+ returnType: User
48
61
  });
49
- console.log(result instanceof TestClass); // true
62
+ console.log(result instanceof User); // true
63
+ console.log(result.name); // Properly deserialized
50
64
  };
51
65
 
52
- fetchClass();
66
+ fetchUser();
53
67
  ```
54
68
 
55
69
  ### POST Request with Body
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@labeg/tfetch",
3
- "version": "0.8.1",
3
+ "version": "0.8.2",
4
4
  "author": "Eugene Labutin",
5
5
  "license": "MIT",
6
6
  "homepage": "https://github.com/LabEG/ts-fetch#readme",