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 232 forks source link

Collection vs URL names #177

Closed Stephane-Peyroutet closed 6 years ago

Stephane-Peyroutet commented 6 years ago

For my REST API calls, I wish to use the widely convention of using URL names with only letters, digits and hypens (eg : customers, purchase-orders, sale-orders, ...). But the InMemoryDbService use collection names that must be valid TS/JS names so I can't directly use hyphens in them. I've read that I can implement a custom "parseRequestUrl" method in my InMemoryDbService but I didn't found any examples on the web for my simple use case. Is this feasible ? Can aynone point me in the right direction or provide a sample code ?

LambdaCruiser commented 6 years ago

This works for me with no issues:

import { InMemoryDbService } from 'angular-in-memory-web-api';

export class InMemHeroService implements InMemoryDbService {
  createDb() {
    let heroes = [
      { id: 1, name: 'Windstorm' },
      { id: 2, name: 'Bombasto' }
    ];
    return {
        'heroes-with-hyphens': heroes
    };
  }
}

There is no restriction on collection names, you can name them however you like, just use the 'key' : value notation.

Stephane-Peyroutet commented 6 years ago

Okay, good one, I completely forgot I could use the 'key': value notation in the return statement. Thanks @LambdaCruiser .