Datasource Http

Edit on GitHub

Datasource Http is an Angular service in the components library that fetches data from URLs via HTTP as configured in the Datasource configuration. Datasource Http supports the caching strategy that can be configured via config and used before the request is made.

Usage

Check out an example usage of the Datasource Http.

Service configuration:

ATTRIBUTE DESCRIPTION
type A datasource type.
url A datasource request URL.
method A datasource request method; GET by default.

Usage example:

<spy-select
    [datasource]="{
        type: 'http',
        url: '/html-request',
        method: 'POST',
    }"
>
</spy-select>

Service registration

Register the service:

declare module '@spryker/datasource' {
    interface DatasourceRegistry {
        http: DatasourceHttpService;
    }
}

@NgModule({
    imports: [
        DatasourceModule.withDatasources({
            http: DatasourceHttpService,
        }),
    ],
})
export class RootModule {}

Interfaces

Datasource Http interfaces:

export interface DatasourceHttpConfig extends DatasourceConfig {
    url: string;
    method?: string;
    dataIn?: DatasourceHttpConfigDataIn;
    cache?: CacheStrategyConfig;
}

export enum DatasourceHttpConfigDataIn {
    Params = 'params',
    Body = 'body',
}