@@ -111,7 +111,7 @@ const data = {
111
111
preferred_format: ' hardback' ,
112
112
}
113
113
};
114
- const restServer = new FakeRest.FetchServer (' http://localhost:3000' );
114
+ const restServer = new FakeRest.FetchServer ({ baseUrl : ' http://localhost:3000' } );
115
115
restServer .init (data);
116
116
fetchMock .mock (' begin:http://localhost:3000' , restServer .getHandler ());
117
117
```
@@ -366,7 +366,7 @@ Operators are specified as suffixes on each filtered field. For instance, applyi
366
366
367
367
``` js
368
368
// initialize a rest server with a custom base URL
369
- const restServer = new FakeRest.Server (' http://my.custom.domain' ); // // only URLs starting with my.custom.domain will be intercepted
369
+ const restServer = new FakeRest.Server ({ baseUrl : ' http://my.custom.domain' }); // only URLs starting with my.custom.domain will be intercepted
370
370
restServer .toggleLogging (); // logging is off by default, enable it to see network calls in the console
371
371
// Set all JSON data at once - only if identifier name is 'id'
372
372
restServer .init (json);
@@ -406,9 +406,9 @@ restServer.setDefaultQuery(function(resourceName) {
406
406
restServer .setBatchUrl (' /batch' );
407
407
408
408
// you can create more than one fake server to listen to several domains
409
- const restServer2 = new FakeRest.Server (' http://my.other.domain' );
409
+ const restServer2 = new FakeRest.Server ({ baseUrl : ' http://my.other.domain' } );
410
410
// Set data collection by collection - allows to customize the identifier name
411
- const authorsCollection = new FakeRest.Collection ([], ' _id' );
411
+ const authorsCollection = new FakeRest.Collection ({ items : [], identifierName : ' _id' } );
412
412
authorsCollection .addOne ({ first_name: ' Leo' , last_name: ' Tolstoi' }); // { _id: 0, first_name: 'Leo', last_name: 'Tolstoi' }
413
413
authorsCollection .addOne ({ first_name: ' Jane' , last_name: ' Austen' }); // { _id: 1, first_name: 'Jane', last_name: 'Austen' }
414
414
// collections have auto incremented identifiers by default but accept identifiers already set
@@ -432,7 +432,7 @@ By default, FakeRest uses an auto incremented sequence for the items identifiers
432
432
import FakeRest from ' fakerest' ;
433
433
import uuid from ' uuid' ;
434
434
435
- const restServer = new FakeRest.Server (' http://my.custom.domain' , () => uuid .v5 ());
435
+ const restServer = new FakeRest.Server ({ baseUrl : ' http://my.custom.domain' , getNewId : () => uuid .v5 () } );
436
436
```
437
437
438
438
This can also be specified at the collection level:
@@ -441,8 +441,8 @@ This can also be specified at the collection level:
441
441
import FakeRest from ' fakerest' ;
442
442
import uuid from ' uuid' ;
443
443
444
- const restServer = new FakeRest.Server (' http://my.custom.domain' );
445
- const authorsCollection = new FakeRest.Collection ([], ' _id' , () => uuid .v5 ());
444
+ const restServer = new FakeRest.Server ({ baseUrl : ' http://my.custom.domain' } );
445
+ const authorsCollection = new FakeRest.Collection ({ items : [], identifierName : ' _id' , getNewId : () => uuid .v5 () } );
446
446
```
447
447
448
448
## Development
0 commit comments