Basically this class is not necessary to be used but if someone overwrites a method of
the base class RestModel
or if creates function that uses the inherited http field.
public fetchImage() {
return this.http.get(this.itemUrl().all('image').build());
}
The concept of ApiUrlMaker
comes from the Restangular
library. A RESTful URL is
theoretically constructed like this: collection[/key]([/collection[/key]])*
.
This class helps to build such URLs however it does not required to have this pattern.
The following is absolutely valid:
new ApiUrlMaker().all('users').all(289342983).all('posts')
Adds two parts to the path to be constructed. Ideally a collection name and a key.
Adds one key to the path to be constructed. Ideally a collection name.
Adds the specified params to the params to be constructed.
Adds the specified param to the params to be constructed.
Constructs the URL string.
const maker = new ApiUrlMaker('/api')
.one('users', 289342983)
.all('posts')
.params({year: 2018})
.param('filter', 'police');
// /api/users/289342983/posts?year=2018&filter=police
console.log(maker.build());