@@ -36,3 +36,128 @@ The session storage works just like the local storage engine with the important
36
36
37
37
## Remote Storage
38
38
39
+ For remote storage, your configuration in ` options.js ` can be set as follow.
40
+
41
+ ``` javascript
42
+ ' Storage' : {
43
+ ' Adapter' : ' RemoteStorage' ,
44
+ ' Store' : ' ' ,
45
+ ' Endpoint' : ' https://foobar.com/gameSave'
46
+ }
47
+ ```
48
+
49
+ Or you may add a store name:
50
+
51
+ ``` javascript
52
+ ' Storage' : {
53
+ ' Adapter' : ' RemoteStorage' ,
54
+ ' Store' : ' MyGame' ,
55
+ ' Endpoint' : ' https://foobar.com/gameSave/'
56
+ }
57
+ ```
58
+
59
+ The storage engine concats the ` Store ` and ` Endpoint ` values as the actual RESTful API ** endpoint url** to use:
60
+
61
+ ```
62
+ https://foobar.com/gameSave/MyGame
63
+ ```
64
+
65
+ ### Implementing the Remote Storage
66
+
67
+ The storage mimic that of a localStorage, which is simple JSON object storage.
68
+
69
+ The ** endpoint url** should implement the below API interface:
70
+
71
+ ---
72
+
73
+ ``` http
74
+ GET [endpoint url]/
75
+ ```
76
+
77
+ {% hint style="info" %}
78
+ Normally, retrieves all the values in the space in a key-value JSON object. If previous storage does not exist, return an empty JSON object: ` {} ` .
79
+
80
+ In keys-listing mode, return all keys stored in the space as a JSON array.
81
+ {% endhint %}
82
+
83
+ ** Parameters**
84
+
85
+ | Name | Description |
86
+ | ---- | ----------- |
87
+ | keys | Boolean. If set to ` true ` , will switch to keys-listing mode. |
88
+
89
+ ---
90
+
91
+ ``` http
92
+ DELETE [endpoint url]/
93
+ ```
94
+
95
+ {% hint style="info" %}
96
+ Clear the entire storage object.
97
+
98
+ Equivlant to
99
+ ``` javascript
100
+ localStorage .clear ();
101
+ ```
102
+ {% endhint %}
103
+
104
+ ---
105
+
106
+ ``` http
107
+ GET [endpoint url]/{key}
108
+ ```
109
+
110
+ {% hint style="info" %}
111
+ Return the value of the key in the storage object.
112
+
113
+ Equivlant to
114
+ ``` javascript
115
+ localStorage .getItem (key);
116
+ ```
117
+ {% endhint %}
118
+
119
+ ---
120
+
121
+ ``` http
122
+ POST [endpoint url]/{key}
123
+ ```
124
+
125
+ {% hint style="info" %}
126
+ Store the value in the storage object under the key.
127
+
128
+ The request body will be the JSON value to store.
129
+
130
+ Equivlant to
131
+ ``` javascript
132
+ localStorage .setItem (key, value);
133
+ ```
134
+ {% endhint %}
135
+
136
+ ---
137
+
138
+ ``` http
139
+ PUT [endpoint url]/{key}
140
+ ```
141
+
142
+ {% hint style="info" %}
143
+ Update a key-value pair. In difference with the set () method, the update
144
+ method will use an Object.assign () in the case of objects so no value is
145
+ lost.
146
+
147
+ The request body will be the JSON value to update the value with.
148
+ {% endhint %}
149
+
150
+ ---
151
+
152
+ ``` http
153
+ DELETE [endpoint url]/{key}
154
+ ```
155
+
156
+ {% hint style="info" %}
157
+ Return the value of the key in the storage object.
158
+
159
+ Equivlant to
160
+ ``` javascript
161
+ localStorage .removeItem (key);
162
+ ````
163
+ {% endhint % }
0 commit comments