Multiple collections in Angular-in-memory-web-api

angular, api, in-memory-database

Solution

Just return it an object with both arrays. In the example from Angular, you see something like

createDb() {
  let heroes = [ .. ]
  return { heroes }
}

If you don't already know this, `{ heroes }` is just shorthand for writing `{ heroes: heroes }`. So if you have two collections, then just add it as a another property

createDb() {
  let heroes = [ .. ];
  let crises = [ .. ];
  return { heroes, crises };
  // or { heroes: heroes, crises: crises }
}

The name of the property returned will be used for the path in the URL. So you can use

/api/heroes/1
/api/crises/1

Problem

How do we create multiple collections using Angular-in-memory-web-api? Not an issue with single collection. But I'm not able to implement it for multiple collections. For example, I want to create say two collections in the memory db - Country and Cities. Any idea, how to do that?

Original source

Related problems