ngx-api-utils is a lean library of utilities and helpers to quickly integrate any HTTP API (REST, Ajax, and any other) with Angular.
ngx-api-utils is a lean library of utilities and helpers to quickly integrate any HTTP API (REST, Ajax, and any other) with Angular.
Inspired by:
Thanks to the respective developers, people and contributors of:
To install the package from npm - run npm install ngx-api-utils
import { NgxApiUtilsModule } from 'ngx-api-utils';
@NgModule({
...
imports: [NgxApiUtilsModule,...]
...
})
export class AppModule { }
The package consists of couple of main services and a module that you would use:
AuthTokenService
to allow you to easily work with any kind of tokens, including but not limited to JWT, Oauth2 with JWT container, etc.
TokenDecoder
TokenPayload
by extending it with the properties you have in the token especially if you are using JWT Token or other that can contain relevant for your application informationTokenStorage
implementation especially if you are not happy with the default localStorage
ApiHttpService
that behaves 100% like Angular's HttpClient
, but helps you by utilizing for you
AuthTokenService
internally and sending the token on each request using ApiAuthorizationHeaderInterceptor
API_HTTP_BASE_URL
ApiDefaultHeadersInterceptor
ApiErrorsInterceptor
and read through it the last errorHttpClient
, just provide it like the defaults are provided with API_HTTP_INTERCEPTORS
injection token e.g. {provide: API_HTTP_INTERCEPTORS, useClass: YourCoolInterceptor, multi: true}
to line up with the rest of the default provided API_HTTP_INTERCEPTORS
ApiAuthGuardService
that is a perfectly sane option of you just have public and private part that needs to be protected based on AuthTokenService
validity and you want a bit more
API_AUTH_GUARD_URL_FOR_AUTHENTICATED
and API_AUTH_GUARD_URL_FOR_AUTHENTICATION
, also a RegExp for API_AUTH_GUARD_PUBLIC_ONLY_ROUTES
NgxApiUtilsModule
that provides a default set of interceptors for API_HTTP_INTERCEPTORS
used by the ApiHttpService
which you can configure through providing your own values for the relevant injection tokensFor more details, please check:
This repository contains a Demo app (TBD) that is intended to show a bit more complex app and how the ngx-api-utils
package fits in.
In the demo beside the usage of ngx-api-utils
I would strongly recommend checking:
ngx-api-utils
(TBD)The project uses the following things, you should get familiar with:
npm run start
npm run start
npm run e2e
(TBD)ngx-api-utils
package itself through npm run ngx-api-utils:build
npm run ngx-api-utils:test
Please feel free to submit PRs for the following things:
We highly appreciate your contribution!