troyanskiy / ngx-resource

Resource (REST) Client for Angular 2
http://troyanskiy.github.io/ngx-resource/
200 stars 46 forks source link

`ResourceCrud` does not always respect global `path` #127

Closed marshall007 closed 7 years ago

marshall007 commented 7 years ago
@ResourceParams({
  path: '/sources',
  url: env.URL,
})
export class SourceResource extends ResourceCRUD<{}, ISource, ISource> { }

const sources = new SourceResource();
sources.query(); // -> GET /sources
sources.get({ id: 'foo' }); // -> GET /foo

Workaround is to just include the path in the url:

@ResourceParams({
  url: `${env.URL}/sources`,
})
export class SourceResource extends ResourceCRUD<{}, ISource, ISource> { }

sources.get({ id: 'foo' }); // -> GET /sources/foo
troyanskiy commented 7 years ago

Hello. Yes, because the resource crud methods already have there's path. Not a lot time ago I have added new param pathPrefix which is solving your case. Simply use like that:

@ResourceParams({
  url: env.URL,
  pathPrefix: '/sources'
})
export class SourceResource extends ResourceCRUD<{}, ISource, ISource> { }

I will close the issue. Feel free to create new with other questions or proposals.