All Projects → abdulhaq-e → Ngrx Json Api

abdulhaq-e / Ngrx Json Api

Licence: mit
A JSON API client for ngrx

Programming Languages

typescript
32286 projects

Labels

Projects that are alternatives of or similar to Ngrx Json Api

Redux Beacon
Analytics integration for Redux and ngrx/store
Stars: ✭ 645 (+923.81%)
Mutual labels:  ngrx
Angular Webpack Starter
A complete Angular 6 and Webpack 4 starter seed with minimal and full featured branches. Full featured branch includes: Material Design 2 (Bootstrap 4 branch available as well), @ngrx, HMR, DLLs and optional use of Universal for server-side rendering - Supports AOT (offline) compilation, sync and lazy loading. Karma/Protractor for e2e/unit tests.
Stars: ✭ 911 (+1346.03%)
Mutual labels:  ngrx
Ngrx Demo
NgRx demo
Stars: ✭ 49 (-22.22%)
Mutual labels:  ngrx
Echoes Player
Echoes Player: the missing Media Player experience for Youtube - Built with Angular (9), ngrx (9), Angular CLI, Boostrap (SASS), Youtube api
Stars: ✭ 802 (+1173.02%)
Mutual labels:  ngrx
Platform
Reactive libraries for Angular
Stars: ✭ 7,020 (+11042.86%)
Mutual labels:  ngrx
Angular Espanol
Recursos, tutoriales y artículos para aprender Angular en español
Stars: ✭ 31 (-50.79%)
Mutual labels:  ngrx
Angular Learning Resources
Curated chronological list of learning resources for Angular, from complete beginner to advanced level
Stars: ✭ 615 (+876.19%)
Mutual labels:  ngrx
Webtorrent Player
WebTorrent Player
Stars: ✭ 60 (-4.76%)
Mutual labels:  ngrx
Road To Master Ngrx Store
A curated guided hyperlinks to learn all there is to know of Ngrx/Store and state management in general
Stars: ✭ 15 (-76.19%)
Mutual labels:  ngrx
Angular Music Player
Angular7.2.x音乐播放器,NGRX,with TypeScript
Stars: ✭ 38 (-39.68%)
Mutual labels:  ngrx
Angularfire
The official Angular library for Firebase.
Stars: ✭ 7,029 (+11057.14%)
Mutual labels:  ngrx
Ngx Remotedata
💥 Slaying a UI Antipattern with Angular
Stars: ✭ 25 (-60.32%)
Mutual labels:  ngrx
Ngrx French Guide
Le guide sur l'utilisation de NGRX dans une application Angular
Stars: ✭ 31 (-50.79%)
Mutual labels:  ngrx
Universal
Seed project for Angular Universal apps featuring Server-Side Rendering (SSR), Webpack, CLI scaffolding, dev/prod modes, AoT compilation, HMR, SCSS compilation, lazy loading, config, cache, i18n, SEO, and TSLint/codelyzer
Stars: ✭ 669 (+961.9%)
Mutual labels:  ngrx
Ngrx Ducks
Improved Coding Experience for NgRx
Stars: ✭ 56 (-11.11%)
Mutual labels:  ngrx
Angular Education
A list of helpful material to develop using Angular
Stars: ✭ 5,451 (+8552.38%)
Mutual labels:  ngrx
Angular Ngrx Data
Angular with ngRx and experimental ngrx-data helper
Stars: ✭ 954 (+1414.29%)
Mutual labels:  ngrx
Angular Ngrx Starter
An opiniated Angular setup based on @angular/cli to kickstart an ngrx project
Stars: ✭ 63 (+0%)
Mutual labels:  ngrx
Angular Reactive Authentication
Angular authentication using reactive extension @ngrx
Stars: ✭ 57 (-9.52%)
Mutual labels:  ngrx
Angular Ngrx Starter
Stars: ✭ 33 (-47.62%)
Mutual labels:  ngrx

ngrx-json-api

CircleCI npm version Coverage Status

A JSON API client library for ngrx.

Note: v1.0 of the library is compatible with old releases of @ngrx tools (< 2). The current version (>= 2) is compatible with the latest versions of @ngrx platform (>= 4)

Documentation

Getting Started

1. Install the library:

npm i ngrx-json-api --save

Install the dependencies:

npm i --save @ngrx/effects @ngrx/store rxjs-compat

Note: rxjs-compat is only needed if you are using rxjs >= 6.0.0

2. Define the resources:

import { ResourceDefinition } from 'ngrx-json-api';

const resourceDefinitions: Array<ResourceDefinition> = [
    { type: 'Article', collectionPath: 'articles' },
    { type: 'Person', collectionPath: 'people' },
    { type: 'Comment', collectionPath: 'comments' },
    { type: 'Blog', collectionPath: 'blogs' }
];

Note that if the type of a resource matches its collectionPath in the URL, then no resource definition is necessary.

3. Import NgrxJsonApiModule providing the above definitions and the API url.

Make sure StoreModule and HttpClientModule are imported beforehand.

@NgModule({
    imports: [
      BrowserModule,
      /* other imports */
      HttpClientModule,
      StoreModule.forRoot(reducers, {}), // reducers, initial state
      NgrxJsonApiModule.configure({
        apiUrl: 'http://localhost.com',
        resourceDefinitions: resourceDefinitions,
      }),
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent]
})
export class AppModule {}

4. Inject NgrxJsonApiService into the component:

import { Component } from '@angular/core';

@Component({
  selector: 'my-component',
})
export class MyComponent {
  constructor(private ngrxJsonApiService: NgrxJsonApiService) {}
}

5. Use the service to interact with the JSON API server and/or state:

For example, to read data from the server and display this data in the view:

import { Component, OnInit } from '@angular/core';
import {
  NgrxJsonApiService,
  QueryResult,
  NGRX_JSON_API_DEFAULT_ZONE,
  Query,
  Direction
} from 'ngrx-json-api';
import { Observable } from 'rxjs';

@Component({
  selector: 'my-component',
  template: `{{ queryResults | async | json }}`
})
export class MyComponent implements OnInit {
  
  public queryResult: Observable<QueryResult>;
  
  constructor(ngrxJsonApiService: NgrxJsonApiService) {  }

  ngOnInit () {
    // a zone represents an independent json-api instance
    const zone = this.ngrxJsonApiService.getZone(NGRX_JSON_API_DEFAULT_ZONE);

    // add query to store to trigger request from server
    const query: Query = {
      queryId: 'myQuery',
      type: 'projects',
      // id: '12' => add to query single item
      params: {
        fields: ['name'],
        include: ['tasks'],
        page: {
          offset: 20,
          limit: 10
        },
        // SortingParam[]
        sorting: [
          { api: 'name', direction: Direction.ASC }
        ],
        // FilteringParam[]
        filtering: [
          { path: 'name', operator: 'EQ', value: 'John' }
        ]
      }
    };

    zone.putQuery({
      query: query,
      fromServer: true // you may also query locally from contents in the store, e.g. new resource
    });

    // select observable to query result holding the loading state and (future) results
    const denormalise = false;

    this.queryResult = this.ngrxJsonApiService.selectManyResults(query.queryId, denormalise);
  }
}

The service is the main API for using ngrx-json-api. The fetching methods return an Observable with the obtained resources stored in a data property.

Example application

For an example application have a look at https://github.com/crnk-project/crnk-example. It combines ngrx-json-api with Crnk as JSON API server implementation to gain a JSON API end-to-end example. @crnk/angular-ngrx is further used to facilitate binding of Angular forms and tables to JSON API. More information can be found at http://www.crnk.io/releases/stable/documentation/#_angular_development_with_ngrx.

Upgrading from v1.0

Upgrade from v1 is really easy; two simple steps:

  1. Remove storeLocation from NgrxJsonApiModule configuration. It's not needed anymore!
  2. Remove NgrxJsonApiReducer from StoreModule configuration.
  3. Import HttpClientModule in the application.

THANKS ❤️

This library wouldn't exist without all the ngrx libraries along with the docs and tools provided with each. Thanks to Ngrx/Store,Effects. Also, the basis of this library is redux-json-api and devour so a huge thanks to the developers of both these JSON API client libs.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].