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: docs/chapters/io.md
+45-11Lines changed: 45 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -30,6 +30,39 @@ An endpoint represents the persistent collection of records serialized to JSON.
30
30
31
31
All IOEndpoint methods must return abortable promises (created with `createIOPromise()`). An IOEndpoint instance is shared by all of the class instances it's attached to and therefore it's normally *must be stateless*.
32
32
33
+
### `endpoint` restfulIO( url, options? )
34
+
35
+
HTTP REST client endpoint. Requires `window.fetch` available natively or through the polyfill. Implements standard BackboneJS REST semantic.
36
+
37
+
All I/O methods append an optional `options.params` object to the URL parameters translating them to string with `JSON.stringify()`.
38
+
39
+
- `record.save()` makes:
40
+
- `POST url`, if the model has no id. Expects to receive `{ id : recordId }`.
41
+
- `PUT url/:id`, if the model has an id.
42
+
- `collection.fetch()` makes `GET url`.
43
+
- `record.destroy()` makes `DELETE url`.
44
+
45
+
Supports URI relative to owner (`./relative/url` resolves as `/owner/:id/relative/url/:id` ).
Endpoint for mock testing. Takes optional array with mock data, and optional `delay` parameter which is the simulated I/O delay in milliseconds.
@@ -77,21 +110,22 @@ const store = new PageStore();
77
110
store.fetch().then( () =>renderUI() );
78
111
```
79
112
80
-
### `endpoint`httpRestIO( url )
113
+
### `endpoint`proxyIO( RecordCtor )
81
114
82
-
<aside class="warning">
83
-
Not implemented yet, is scheduled for v2.1
84
-
</aside>
115
+
Create IO endpoint from the Record class. This endpoint is designed for use on the server side with a data layer managed by Type-R.
116
+
117
+
Assuming that you have Type-R records with endpoints working with the database, you can create an endpoint which will use
118
+
an existing Record subclass as a transport. This endpoint can be connected to the RESTful endpoint API on the server side which will serve JSON to the restfulIO endpoint on the client.
85
119
86
-
Simple HTTP REST endpoint.
120
+
An advantage of this approach is that JSON schema will be transparently validated on the server side by the Type-R.
87
121
88
-
- `create()` makes `POST url`, expecting to receive `{ id : recordId }` or other object used to update the record.
89
-
- `read()` makes `GET url/:id`.
90
-
- `update()` makes `PUT url/:id`.
91
-
- `destroy()` makes `DELETE url/:id`.
92
-
- `list()` makes `GET url`.
122
+
```javascript
123
+
import { proxyIO } from'type-r/endpoint/proxy'
124
+
125
+
...
93
126
94
-
All I/O methods append an optional `options.params` object to the URL parameters translating them to string using `JSON.stringify()`.
0 commit comments