Skip to content

Commit 6e7fdc2

Browse files
committed
Combine docs into readme and remove vuepress
1 parent 7ac9086 commit 6e7fdc2

File tree

8 files changed

+240
-5803
lines changed

8 files changed

+240
-5803
lines changed

README.md

Lines changed: 110 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,116 @@ client.all().then(results => console.log(results));
5959

6060
## Usage
6161

62-
For more information on usage, see the [`@reststate/client` docs](https://client.reststate.codingitwrong.com).
62+
### Reading Data
63+
64+
#### all
65+
66+
To retrieve all of the records for a resource, call the `all()` method. The method returns a promise that will resolve to the server's JSON response:
67+
68+
```javascript
69+
resource.all().then(response => console.log(response.data));
70+
```
71+
72+
#### find
73+
74+
To retrieve a single record by ID, call the `find()` method:
75+
76+
```javascript
77+
resource.find({ id: 42 }).then(response => console.log(response.data));
78+
```
79+
80+
#### where
81+
82+
To filter/query for records based on certain criteria, use the `where` method, passing it an object of filter keys and values to send to the server:
83+
84+
```javascript
85+
const filter = {
86+
category: 'whizbang',
87+
};
88+
resource.where({ filter }).then(response => console.log(response.data));
89+
```
90+
91+
#### related
92+
93+
Finally, to load records related via JSON:API relationships, use the `related` method. A nested resource URL is constructed like `categories/27/widgets`. (In the future we will look into using HATEOAS to let the server tell us the relationship URL).
94+
95+
```javascript
96+
const parent = {
97+
type: 'category',
98+
id: 27,
99+
};
100+
101+
resource.related({ parent }).then(response => console.log(response.data));
102+
```
103+
104+
By default, the name of the relationship on `parent` is assumed to be the same as the name of the other model: in this case, `widgets`. In cases where the names are not the same, you can explicitly pass the relationship name:
105+
106+
```javascript
107+
const parent = {
108+
type: 'categories',
109+
id: 27,
110+
};
111+
112+
const relationship = 'purchased-widgets';
113+
114+
resource
115+
.related({ parent, relationship })
116+
.then(response => console.log(response.data));
117+
```
118+
119+
#### Options
120+
121+
All read methods take an optional `options` property, consisting of an object of additional options to pass. Each key/value pair in the object is translated into a query string parameter key/value pair:
122+
123+
```js
124+
resource.all({
125+
options: {
126+
include: 'comments',
127+
},
128+
});
129+
130+
// requests to widgets?include=comments
131+
```
132+
133+
### Writing
134+
135+
#### create
136+
137+
Creates a new record. The object passed in should follow the JSON:API object format, but the `type` can be omitted:
138+
139+
```js
140+
widgetResource.create({
141+
attributes: {
142+
'name': 'My Widget',
143+
'creation-date': '2018-10-07',
144+
},
145+
});
146+
```
147+
148+
This isn't just limited to `attributes`; `relationships` can be passed in too.
149+
150+
#### update
151+
152+
Updates a record. Takes the `id` of the record and the `attributes` and/or `relationships` to update. No `type` argument is required, but if passed in it's ignored, so you can pass in a full record if you like.
153+
154+
```js
155+
widgetResource.update({
156+
id: '42',
157+
attributes: {
158+
name: 'My Updated Widget',
159+
},
160+
});
161+
```
162+
163+
This isn't just limited to `attributes`; `relationships` can be passed in too.
164+
165+
#### delete
166+
167+
Deletes the passed-in record. Only the `id` property is used, so you can pass either a full record or just the ID:
168+
169+
```js
170+
widgetResource.delete({ id: 42 });
171+
```
63172

64173
## License
65174

docs/.vuepress/config.js

Lines changed: 0 additions & 22 deletions
This file was deleted.

docs/README.md

Lines changed: 0 additions & 38 deletions
This file was deleted.

docs/installation.md

Lines changed: 0 additions & 25 deletions
This file was deleted.

docs/reading-data.md

Lines changed: 0 additions & 70 deletions
This file was deleted.

docs/writing-data.md

Lines changed: 0 additions & 39 deletions
This file was deleted.

package.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,11 @@
88
"license": "Apache-2.0",
99
"scripts": {
1010
"test": "jest --watchAll",
11-
"lint": "eslint \"{src,test}/*.js\"",
12-
"docs:dev": "vuepress dev docs",
13-
"docs:build": "vuepress build docs"
11+
"lint": "eslint \"{src,test}/*.js\""
1412
},
1513
"devDependencies": {
1614
"@babel/core": "^7.1.2",
1715
"@babel/preset-env": "^7.1.0",
18-
"@vuepress/plugin-google-analytics": "^1.0.1",
1916
"acorn": "^8.0.1",
2017
"babel-core": "^7.0.0-0",
2118
"babel-eslint": "^10.0.1",
@@ -28,7 +25,6 @@
2825
"kind-of": "^6.0.3",
2926
"prettier": "2.1.2",
3027
"serialize-javascript": "^5.0.1",
31-
"set-value": "^4.0.1",
32-
"vuepress": "^1.0.1"
28+
"set-value": "^4.0.1"
3329
}
3430
}

0 commit comments

Comments
 (0)