11

I was using "angular-in-memory-web-api" to mock my REST web api, however now I am have started writing the actual web api and I want to replace the "angular-in-memory-web-api" step by step.

Example: I have written following asp.net web api /api/values however when I issue http.get() request using above api url angular tries to serve it using "angular-in-memory-web-api", however in this case I want to bypass "angular-in-memory-web-api" so that request is entertained by my actual web api controller.

3 Answers3

31

you can set passThruUnknownUrl to forward to real backend for un-matching endpoints

e.g.,

InMemoryWebApiModule.forRoot(InMemoryDataService, {
  passThruUnknownUrl: true
}),
Liam
  • 27,717
  • 28
  • 128
  • 190
xmlking
  • 626
  • 8
  • 16
1

You can try by removing InMemoryWebApiModule.forRoot(InMemoryDataService) from your app.module. If you have done so already, showing some code would be helpful.

Also, consider using Postman to verify your new service

Juan Herrera
  • 810
  • 1
  • 10
  • 16
  • removing InMemoryWebApiModule.forRoot(InMemoryDataService) from app module bypass the in-memory web api in whole, however as mentioned in my question I want to enable disable angular in-memory web api for selective services. Is it possible? – Shoket Mahmood Ahmed Jan 11 '17 at 21:12
  • 1
    I see your point now, sorry I didn't get it at first. That's an interesting question. I tried something similar a few days ago unsuccessfully. As stated in the docs: "It intercepts Angular Http requests that would otherwise go to the remote server...". So I think you can't, but you can always create an issue referencing this question, maybe they can help you out – Juan Herrera Jan 12 '17 at 11:38
0

in app.module.ts

import { HttpClientInMemoryWebApiModule } from 'angular-in-memory-web-api';
import { InMemoryDataService } from './my-module/services/in-memory-data.service';

in app.module.ts imports array

HttpClientInMemoryWebApiModule.forRoot(InMemoryDataService, { dataEncapsulation: false, passThruUnknownUrl: true })

passThruUnknownUrl related doc

tinystone
  • 369
  • 3
  • 6