ngrx-json-api
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:
; ;
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.
4. Inject NgrxJsonApiService
into the component:
;
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:
;;;
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:
- Remove
storeLocation
fromNgrxJsonApiModule
configuration. It's not needed anymore! - Remove
NgrxJsonApiReducer
fromStoreModule
configuration. - 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.