Skip to content

Angular - http query module based on the @ngrx/store package.

Notifications You must be signed in to change notification settings

ng-sm/http-query

Repository files navigation

HTTP Query module based on the @ngrx/store package.

Installation

yarn add @ngsm/http-query or npm i @ngsm/http-query --save

Requirements

Library requires @ngrx/store module.

Usage

Import QueryModule in your app.module.ts:

import { QueryModule } from '@ngsm/query';

...,
@NgModule({
  ....,
  imports: [
    ....,
    QueryModule
  ]
}
...
import { QueryFacade } from '@ngsm/query';
import { HttpClient } from '@angular/common/http';

@Component({
  selector: 'app-cars',
  templateUrl: './cars.component.html',
})
export class CarsComponent implements OnInit {
  // Available methods:
  loader$ = this.queryFacade.isInProgress$('cars');
  query$ = this.queryFacade.query$<YOUR_TYPE>('getCars');
  response$ = this.queryFacade.response$<YOUR_TYPE>('getCars');
  body$ = this.queryFacade.body$<YOUR_TYPE>('getCars');
  error$ = this.queryFacade.error$('getCars');
  status$ = this.queryFacade.status$('getCars');

  constructor(
    private httpClient: HttpClient,
    private queryFacade: QueryFacade,
  ) {}

  ngOnInit() {
    this.getCars().subscribe();
  }

  getCars(): Observable<YOUR_TYPE> {
    return this.http.get('API_URL', {
      headers: { queryName: 'getCars', queryGroups: ['cars'] }
    });
  }
}

Author

Sebastian Musiał

kontakt@sebastianmusial.pl

@sebamusial

About

Angular - http query module based on the @ngrx/store package.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published