Instead of trying to make this ugly "two HTTP", angular-in-memory-web-apiprovides a few options.
Starting with 0.1.3, there is a configuration property for sending all not found collection calls to regular XHR.
InMemoryWebApiModule.forRoot(MockData, {
passThruUnknownUrl: true
})
, , , XHR. , , db in-memory, .
class MockData implements InMemoryDbService {
createDb() {
let cats = [];
let dogs = [];
return {
cats,
};
}
}
dogs , .
. , .
MockData, , get, MockData HttpMethodInterceptorArgs.
class MockData implements InMemoryDbService {
get(args: HttpMethodInterceptorArgs) {
}
}
HttpMethodInterceptorArgs ( , )
HttpMethodInterceptorArgs: {
requestInfo: {
req: Request (original request object)
base
collection
collectionName
headers
id
query
resourceUrl
}
passThruBackend: {
The Original XHRBackend (in most cases)
}
config: {
this is the configuration object you pass to the module.forRoot
}
db: {
this is the object from creatDb
}
}
, ,
get(args: HttpMethodInterceptorArgs) {
return args.passthroughBackend.createConnection(args.requstInfo.req).response
}