3

I am working with Angular In Memory Web API for making API calls locally without actual RESTful APIs from my Java application. I created the URLs in In memory Data service as same like LIVE RESTful API URLs.

export class UserMockService {

  SERVER_URL: string = 'http://localhost:8080/api/users';
  constructor(private httpClient: HttpClient) { }

  public getUsers(){
    return this.httpClient.get(this.SERVER_URL);
  }
  public getUser(id) {
    return this.httpClient.get(`${this.SERVER_URL}?userId=` + userNumber);
  }

Here is my Data service which implements the In Memory Web API module return the created DB of users.

export class UserMockApiService implements InMemoryWebApiModule {
  constructor() { }
  createDb(){
    const users = [
      {
        id: 1001,
      },    {
        id: 2001,
      }     ];
    return {users};
  }

I am aware of the config passThruUnknownUrl: true, which can look for my RESTful API, if it cant find in memory API the exact path not matches.

I have my own Java Application RESTful API available now, for getting the users list in same URL http://localhost:8080/api/users

Now, I want to use my JAVA API for getting users list instead of In memory Web API, as it is ready to get the real users list.

But for other APIs like getUserById, my JAVA API is not available yet. So I would like to use In memory web API for these.

Whichever API is available in my Java app, I want my Http calls to go their and look into that first, if its not available in my Java app, then only it has to look into In memory Web API.

Is there any configuration for this to have some priority.

J Query
  • 305
  • 4
  • 19

0 Answers0