You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+115-4Lines changed: 115 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,15 +3,86 @@
3
3
4
4
# @monade/json-api-parser
5
5
6
-
A parser for [JSON:API](https://jsonapi.org/) format that maps data to models using decorators, inspired by retrofit.
6
+
This library provides a parser for the [JSON:API](https://jsonapi.org/) format, enabling seamless mapping of JSON data to TypeScript/JavaScript models using decorators.
This decorator acts as the entry point for declaring a JSON:API model. It maps a JSON:API object type to the decorated class.
47
+
48
+
```typescript
49
+
@JSONAPI("posts")
50
+
classPostextendsModel {}
51
+
```
52
+
53
+
**`@Attr([name?: string, options?: { parser?: Function, default?: any }])`**
54
+
55
+
This decorator is used for declaring attributes on a JSON:API model. You can optionally specify a different name for the attribute, a default value and a parser function to transform the data.
56
+
57
+
```typescript
58
+
@JSONAPI("posts")
59
+
classPostextendsModel {
60
+
@Attr() title:string;
61
+
}
62
+
```
63
+
64
+
**`@Rel([name?: string, options?: { parser?: Function, default?: any }])`**
65
+
66
+
Use this decorator to declare relationships between JSON:API models. You can optionally specify a different name for the relationship, a default value and a parser function to transform the data.
67
+
68
+
```typescript
69
+
@JSONAPI("posts")
70
+
classPostextendsModel {
71
+
@Rel() author:User;
72
+
}
73
+
```
74
+
75
+
### The Parser
76
+
The Parser class is responsible for transforming JSON:API objects into instances of the declared models. To use it, create a new instance of `Parser` and call its `run<T>` method.
0 commit comments