2

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?

Gitnik
  • 564
  • 7
  • 26

1 Answers1

1

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 };
}
ktretyak
  • 27,251
  • 11
  • 40
  • 63
  • Wow, this is an ancient question, I totally forgot :D Yes, the `angular-in-memory-web-api` does not support such a configurations. There are alternative JS api libraries, but either they don't support this or are too complicated to test in short amount of time (at least for me). In the end I wrote my own test API backend as a simple python script that return JSON files placed on the filesystem. – Gitnik Jan 28 '19 at 07:35