Skip to content

Commit 0bb3cd1

Browse files
committed
Documentation updated and new tags added
~ README.md - more information about usage provided ~ package.json - new tags added
1 parent bd601ed commit 0bb3cd1

File tree

4 files changed

+165
-6
lines changed

4 files changed

+165
-6
lines changed

README.md

Lines changed: 144 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,144 @@
1-
# Normalize-JSON-API
2-
Normalizing a JSON:API styled server response
1+
# Normalize JSON:API Response
2+
3+
![Logo](/img/logo.png)
4+
5+
[![npm version](https://img.shields.io/npm/v/normalize-json-api-response.svg)](https://www.npmjs.com/package/normalize-json-api-response)
6+
[![npm downloads](https://img.shields.io/npm/dt/normalize-json-api-response.svg)](https://www.npmjs.com/package/normalize-json-api-response)
7+
[![license](https://img.shields.io/npm/l/normalize-json-api-response.svg)](https://github.com/SinestroWhite/Normalize-JSON-API/blob/master/LICENSE)
8+
9+
> *Normalize JSON:API Response (NJAR) is not only designed to simplify JSON:API responses but also to make them easy developer friendly.*
10+
>
11+
> *Created by Sinestro White with :heart: !*
12+
13+
## Features
14+
15+
- **Easy installation and integration** - No complicated actions
16+
- **JSON:API simplification**
17+
- **No need to correct the normalized response**
18+
- **Front-end design friendly** - Makes response data easy to display with a for-loop
19+
- **No schema required**
20+
- **No dependencies** 👌
21+
22+
## Installation
23+
24+
Using [npm](https://www.npmjs.com/package/normalize-json-api-response):
25+
26+
```
27+
$ npm i normalize-json-api-response
28+
```
29+
30+
Then, using a module bundler that supports either CommonJS or ES2015 modules, such as [webpack](https://github.com/webpack/webpack):
31+
32+
```js
33+
import normalize from 'normalize-json-api-response';
34+
```
35+
36+
## Usage
37+
38+
### Basic Example
39+
40+
When working with the JSON:API specification, the response body of any request is optimized and it can get difficult to
41+
do computations. The main information is contained in the "data" property but if there are relations to other tables they
42+
are put in the "included" property.
43+
44+
```js
45+
//Example server response
46+
const data = {
47+
data: {
48+
type: "articles",
49+
id: "1",
50+
attributes: {
51+
title: "JSON:API paints my bikeshed!"
52+
},
53+
relationships: {
54+
author: {
55+
data: { type: "people", id: "9" }
56+
}
57+
}
58+
},
59+
included: [
60+
{
61+
type: "people",
62+
id: "9",
63+
attributes: {
64+
firstName: "Dan",
65+
lastName: "Gebhardt",
66+
twitter: "dgeb"
67+
}
68+
}
69+
]
70+
};
71+
72+
```
73+
74+
Normalize JSON:API Response (NJAR) solves the problem with the JSON:API response optimization by moving every item from
75+
"included" to the item from "data" it belongs to.
76+
77+
```js
78+
import normalize from 'normalize-json-api-response';
79+
console.log(normalize(data));
80+
81+
// Normalized object
82+
// {
83+
// "people": [
84+
// {
85+
// "id": "9",
86+
// "attributes": {
87+
// "firstName": "Dan",
88+
// "lastName": "Gebhardt",
89+
// "twitter": "dgeb"
90+
// }
91+
// }
92+
// ],
93+
// "articles": [
94+
// {
95+
// "id": "1",
96+
// "attributes": {
97+
// "title": "JSON:API paints my bikeshed!"
98+
// },
99+
// "relationships": {
100+
// "people": [
101+
// {
102+
// "type": "people",
103+
// "id": "9",
104+
// "attributes": {
105+
// "firstName": "Dan",
106+
// "lastName": "Gebhardt",
107+
// "twitter": "dgeb"
108+
// }
109+
// }
110+
// ]
111+
// }
112+
// }
113+
// ]
114+
// }
115+
116+
```
117+
118+
As you can see the "articles" property is an array of objects so that every item can be accessed easily with a simple for-loop.
119+
The information from "included" has been moved in the "relationships" property of every item in "articles".
120+
121+
## Why should I use this?
122+
123+
There are already a number of great JSON:API normalizing packages out there (for instance, [json-api-normalizer](https://www.npmjs.com/package/json-api-normalizer) is fantastic).
124+
However, most of those packages do not provide a simple way to access the included information from every "data" item,
125+
which has some severe limitations. In this case, you have to create additional functions to correct the normalized response.
126+
127+
# FAQ
128+
129+
## Dependencies
130+
131+
NJAR has no dependencies.
132+
133+
## Reporting Issues
134+
135+
If believe you've found an issue, please [report it](https://github.com/SinestroWhite/Normalize-JSON-API/issues) along with any relevant details to reproduce it.
136+
137+
## Asking for help
138+
139+
Please file an issue for personal support requests. Tag them with `question`.
140+
141+
## Contributions
142+
143+
Yes please! Feature requests / pull requests are welcome.
144+

img/logo.png

43.2 KB
Loading

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "normalize-json-api",
2+
"name": "normalize-json-api-response",
33
"version": "1.0.0",
44
"description": "Normalizing a JSON:API styled server response",
55
"main": "dist/index.js",
@@ -14,12 +14,29 @@
1414
"keywords": [
1515
"normalize",
1616
"json:api",
17+
"jsonapi",
18+
"json-api",
1719
"json",
18-
"api"
20+
"api",
21+
"vue",
22+
"angular",
23+
"react",
24+
"normalize-json-api",
25+
"json-api-normalize",
26+
"normalize",
27+
"json api typescript",
28+
"json-api-typescript",
29+
"jsonapi-typescript",
30+
"json-api",
31+
"data converter",
32+
"data formatter",
33+
"convertor",
34+
"formatter"
1935
],
2036
"author": "Sinestro White",
2137
"license": "MIT",
2238
"devDependencies": {
2339
"typescript": "^3.3.3333"
24-
}
40+
},
41+
"dependencies": {}
2542
}

0 commit comments

Comments
 (0)