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
+46-27Lines changed: 46 additions & 27 deletions
Original file line number
Diff line number
Diff line change
@@ -83,26 +83,10 @@ Examples:
83
83
GET api/heroes?name=^j // 'j' is a regex; returns heroes whose name starting with 'j' or 'J'
84
84
GET api/heroes.json/42 // ignores the ".json"
85
85
```
86
-
<aid="commands"></a>
87
-
## Commands
88
86
89
-
The service also accepts "commands" that can, for example, reconfigure the service and reset the database.
87
+
The in-memory web api service processes these requests against a "database" - a set of named collections - that you define during setup.
90
88
91
-
When the last segment of the _api base path_ is "commands", the `collectionName` is treated as the _command_.
92
-
Example URLs:
93
-
```
94
-
commands/resetdb // Reset the "database" to its original state
95
-
commands/config // Get or update this service's config object
96
-
```
97
-
98
-
Usage:
99
-
```
100
-
http.post('commands/resetdb', undefined);
101
-
http.get('commands/config');
102
-
http.post('commands/config', '{"delay":1000}');
103
-
```
104
-
105
-
## Basic usage
89
+
## Basic setup
106
90
107
91
Create an `InMemoryDataService` class that implements `InMemoryDbService`.
108
92
@@ -126,7 +110,17 @@ export class InMemHeroService implements InMemoryDbService {
126
110
}
127
111
```
128
112
129
-
>This library _currently_ assumes that every collection has a primary key called `id`.
113
+
**Notes**
114
+
115
+
* The in-memory web api library _currently_ assumes that every collection has a primary key called `id`.
116
+
117
+
* The `createDb` method can be synchronous or asynchronous.
118
+
It would have to be asynchronous if you initialized your in-memory database service from a JSON file.
119
+
Return the database _object_, an _observable_ of that object, or a _promise_ of that object. The tests include an example of all three.
120
+
121
+
* The client can send a [`resetDb` command](#commands) request which calls your `createDb` again, passing in the command request information.
122
+
123
+
### Import the in-memory web api module
130
124
131
125
Register your data store service implementation with the `HttpClientInMemoryWebApiModule`
132
126
in your root `AppModule.imports`
@@ -155,12 +149,7 @@ to ensure that the in-memory backend provider supersedes the Angular version.
155
149
156
150
* You can setup the in-memory web api within a lazy loaded feature module by calling the `.forFeature` method as you would `.forRoot`.
157
151
158
-
* The `createDb` method can be synchronous or asynchronous.
159
-
so you can initialize your in-memory database service from a JSON file.
160
-
Return the database object, an observable of that object, or a promise of that object.
161
-
The in-memory web api service calls `createDb` (a) when it handles the _first_`HttpClient` (or `Http`) request and (b) when it receives a `POST resetdb` request.
162
-
163
-
### Using with the older Angular _Http_ module
152
+
### Setup for the older Angular _Http_ module
164
153
165
154
You can still use the in-memory web api with the older `Http` module.
166
155
@@ -180,10 +169,10 @@ imports: [
180
169
})
181
170
exportclassAppModule { ... }
182
171
```
183
-
### Using both Angular HTTP modules
172
+
### Setup for both Angular HTTP modules
184
173
185
174
Perhaps you have a hybrid app with BOTH Angular modules
186
-
because you're migrating to `HttpClient` from 'Http`.
175
+
because you're migrating to `HttpClient` from `Http`.
187
176
Or perhaps you've used this library before and you don't have time
188
177
at this moment to re-do your module setup.
189
178
@@ -224,6 +213,8 @@ See also the example source code in the official Angular.io documentation such a
224
213
# Advanced Features
225
214
Some features are not readily apparent in the basic usage described above.
226
215
216
+
## Configuration arguments
217
+
227
218
The `InMemoryBackendConfigArgs` defines a set of options. Add them as the second `forRoot` argument:
0 commit comments