aurelia-api
Version:
A simple api wrapper around aurelia-fetch-client
52 lines (38 loc) • 1.06 kB
Markdown
# Usage
After configuring the endpoints, you'll probably want to use them, too.
## Get endpoint
There are currently two ways to get an endpoint.
### Config
You can use the `.getEndpoint()` method on the `Config` instance from aurelia-api.
```js
import {inject} from 'aurelia-framework';
import {Config} from 'aurelia-api';
(Config)
export class MyClass {
constructor(config) {
this.apiEndpoint = config.getEndpoint('api');
}
}
```
### Resolver
Aurelia-api also ships with a custom resolver that makes your code aesthetically pleasing.
```js
import {inject} from 'aurelia-framework';
import {Endpoint} from 'aurelia-api';
(Endpoint.of('api'))
export class MyClass {
constructor(apiEndpoint) {
this.apiEndpoint = apiEndpoint;
}
}
```
To use Resolvers with use as parameter decorator
```js
import {inject, autoinject} from 'aurelia-framework';
import {Endpoint, Rest} from 'aurelia-api';
()
export class MyClass {
constructor(public (Endpoint.of('api')) apiEndpoint: Rest) {
}
}
```