angular / in-memory-web-api

The code for this project has moved to the angular/angular repo. This repo is now archived.
MIT License
1.18k stars 231 forks source link

Set a collection in a nested endpoint which is already a collection #139

Closed damsorian closed 7 years ago

damsorian commented 7 years ago

Hi!

I need to set a collection in a nested endpoint which is already a collection and I don't want to take it as an ID. is there any easy way?

Something like this:

createDb() {
  return {
    // api/heroes
    'heroes': [
      { id: 1, name: 'Windstorm' },
      { id: 2, name: 'Bombasto' },
    ],
    // api/heroes/warriors
    'heroes/warriors': [
      { id: 1, name: 'Pepe' },
      { id: 2, name: 'Grillo' },
    ],
  };
}

Thanks!

wardbell commented 7 years ago

You should be able to do that by overriding the parseRequestUrl in your InMemoryDbService to get what you want.

See HeroInMemDataOverrideService for an example of a parseRequestUrl override that turns /foo/heroes into just /heroes. You could do something similar to translate to a collection named warriors or heroes-warriors.

If you REALLY want to have a collection named heroes-warriors, you can but you'll have to play around with the result of the ParsedRequestUrl