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 Answers 3

32

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

e.g.,

InMemoryWebApiModule.forRoot(InMemoryDataService, {
  passThruUnknownUrl: true
}),
Sign up to request clarification or add additional context in comments.

1 Comment

very important to know!
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

2 Comments

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?
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
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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.