angularangular-in-memory-web-api

Nested in-memory-web-api i.e. longer uri


I'm trying to develop an application using in-memory-web-api, however, I'm not sure how to deal with longer URI patterns.

For example, I need to fetch some configuration data from the server using /api/v1/configuration/manager and /api/v1/configuration/customer. I've structured my dummy data as follows:

const v1 = [{
  configuration: {
    manager: [{...}, {...}, ...],
    customer: [{...}, {...}, ...]
  }
}];

But I 404 error. This is how I formed GET request:

public getManagerConfig() {
  return this.http.get<any[]>('/api/v1/configuration/manager');
}

The idea is to map as best as possible my API in angular during the development. How do I deal with this kind of nested data and URIs?


Solution

  • It seems that the module angular-in-memory-web-api has not been designed for such cases. As a bypass, try this:

    1. Your apiBase should be api.
    2. Items in your array v1 should have property id = 'configuration/*':
    createDb() {
      const v1 = [
        {
          id: 'configuration/manager',
          data: [{...}, {...}, ...]
        },
        {
          id: 'configuration/customer',
          data: [{...}, {...}, ...]
        }
      ];
    
      return { v1 };
    }