1.0.9 • Published 1 year ago

exc-rest-v2 v1.0.9

Weekly downloads
32
License
-
Repository
-
Last release
1 year ago

Module Exc-Rest-V2

Content
  • ExcRestModule
Services
  • ExcRestService
  • ExcTranslateService
Enumerations
  • ExcRestMode
Interfaces
  • IExcDataFilter
  • IExcDataPaging
  • IExcDataSort
  • IExcMetaInfo
  • IExcRestConfig
  • IExcRestRequestConfig
  • IRequestOptions
Pipes
  • ExcDatePipe
  • ExcCurrencyPipe

Dependencies

  • exc-core-v2

Install

To install ExcRestModule into your project use

npm i exc-rest-v2

ExcRestService

Dependencies

  • Register environment into ExcCoreModule.Config() with ExcCoreModule.RegisterConfig('Environment',environment)
  • Prepare environment.ts for the endpoints
export const environment = {
  production: false,
  sec: {},
  rest: {
    ServiceUrl: 'Base URL of Service with trailing /',
    LoginUrl: 'Base URL of Security Service with trailing /',
    Endpoints: {
      PasswordSettings: 'PasswordSettings'
    }
  }
};

Setup

To use ExcRestService you have to do preparations in your project.

  1. app.module.ts
//...
import {environment} from '../environments/environment';
import {ExcCoreModule} from 'exc-core-v2';
import {ExcRestModule, ExcRestService, ExcRestMode} from 'exc-rest-v2';
import {AppComponent} from './app.component';

@NgModule({
  declarations: [AppComponent],
  imports: [
    BrowserModule,
    AppRoutingModule,
    ExcCoreModule,
    ExcRestModule
    //...
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule {
  constructor(private excRest: ExcRestService) {
    ExcCoreModule.RegisterConfig('Environment', environment);
    excRest.Mode = ExcRestMode.GROOT; /* GROOT is default-mode this line could be removed */
  }
}
  1. app.component.ts
//...
import {ExcCoreModule} from 'exc-core-v2';
import {ExcRestService} from 'exc-rest-v2';

//...
export class AppComponent implements OnInit {
//...
  constructor(private excRestService: ExcRestService) {
  }
}

Definitions

Properties

NameTypeDescription
ModeExcRestModeGet or set the mode of ExcRestService.(Default: ExcRestMode.GROOT)

Methods

get(url, config?, mode?)
Parameters
NameTypeDescription
urlstringURL for the request
config?IExcRestRequestConfig undefined(optional) configuration for the request.
mode?ExcRestMode undefined(optional) mode for the call, if different from default mode in ExcRestService
Returns

Observable<any>

Examples
const excRest = ExcCoreModule.Services().ExcRest;
const url = 'https://localhost/test';
const config: ExcRestRequestConfig = {}

excRest.get(url).subscribe((response: any) => {
})
excRest.get(url, config).subscribe((response: any) => {
})
excRest.get(url, config, ExcRestMode.BASIC).subscribe((response: any) => {
})
sget(url, id, config?, mode?)
Parameters
NameTypeDescription
urlstringURL for the request
idstringID of the request to identify the correct last response of multiple calls
config?IExcRestRequestConfig undefined(optional) configuration for the request.
mode?ExcRestMode undefined(optional) mode for the call, if different from default mode in ExcRestService
Returns

Observable<any>

Examples
const callID = '08154711'
const excRest = ExcCoreModule.Services().ExcRest;
const url = 'https://localhost/test';
const config: ExcRestRequestConfig = {}

excRest.sget(url, callID).subscribe((response: any) => {
})
excRest.sget(url, callID, config).subscribe((response: any) => {
})
excRest.sget(url, callID, config, ExcRestMode.BASIC).subscribe((response: any) => {
})
put(url, data, config?, mode?)
Parameters
NameTypeDescription
urlstringURL for the request
dataanyPayload of the request
config?IExcRestRequestConfig undefined(optional) configuration for the request.
mode?ExcRestMode undefined(optional) mode for the call, if different from default mode in ExcRestService
Returns

Observable<any>

Examples
const excRest = ExcCoreModule.Services().ExcRest;
const url = 'https://localhost/test';
const config: ExcRestRequestConfig = {}
const data: { Name: 'Doe', Firstname: 'John' }

excRest.put(url, data).subscribe((response: any) => {
})
excRest.put(url, data, config).subscribe((response: any) => {
})
excRest.put(url, data, config, ExcRestMode.BASIC).subscribe((response: any) => {
})
sput(url, data, id, config?, mode?)
Parameters
NameTypeDescription
urlstringURL for the request
dataanyPayload of the request
idstringID of the request to identify the correct last response of multiple calls
config?IExcRestRequestConfig undefined(optional) configuration for the request.
mode?ExcRestMode undefined(optional) mode for the call, if different from default mode in ExcRestService
Returns

Observable<any>

Examples
const callID = '08154711'
const excRest = ExcCoreModule.Services().ExcRest;
const url = 'https://localhost/test';
const config: ExcRestRequestConfig = {}
const data: { Name: 'Doe', Firstname: 'John' }

excRest.sput(url, data, id).subscribe((response: any) => {
})
excRest.sput(url, data, id, config).subscribe((response: any) => {
})
excRest.sput(url, data, id, config, ExcRestMode.BASIC).subscribe((response: any) => {
})
post(url, data, config?, mode?)
Parameters
NameTypeDescription
urlstringURL for the request
dataanyPayload of the request
config?IExcRestRequestConfig undefined(optional) configuration for the request.
mode?ExcRestMode undefined(optional) mode for the call, if different from default mode in ExcRestService
Returns

Observable<any>

Examples
const excRest = ExcCoreModule.Services().ExcRest;
const url = 'https://localhost/test';
const config: ExcRestRequestConfig = {}
const data: { Name: 'Doe', Firstname: 'John' }

excRest.post(url, data).subscribe((response: any) => {
})
excRest.post(url, data, config).subscribe((response: any) => {
})
excRest.post(url, data, config, ExcRestMode.BASIC).subscribe((response: any) => {
})
delete(url, data?, config?, mode?)
Parameters
NameTypeDescription
urlstringURL for the request
data?any(optional) Payload of the request
config?IExcRestRequestConfig undefined(optional) configuration for the request.
mode?ExcRestMode undefined(optional) mode for the call, if different from default mode in ExcRestService
Returns

Observable<any>

Examples
const excRest = ExcCoreModule.Services().ExcRest;
const url = 'https://localhost/test';
const config: ExcRestRequestConfig = {}
const data: { ID: 11, Name: 'Doe', Firstname: 'John' }

excRest.delete(url).subscribe((response: any) => {
})
excRest.delete(url, data).subscribe((response: any) => {
})
excRest.delete(url, data, config).subscribe((response: any) => {
})
excRest.delete(url, data, config, ExcRestMode.BASIC).subscribe((response: any) => {
})
computeUrl(name, pObj?)
Parameters
NameTypeDescription
namestringFull-URL or Name of the endpoint in the rest config in environment.ts
pObj?any(optional) Object with placeholder replacement for the url
Returns

string

Examples
const excRest = ExcCoreModule.Services().ExcRest;
const url = 'https://localhost/test/{ID}';
const data: { ID: 11, Name: 'Doe', Firstname: 'John' }

excRest.computeUrl(url); // returns https://localhost/test/{ID}
excRest.computeUrl(url, data); // returns https://localhost/test/11?Name=Doe&Firstname=John

ExcTranslateService

Dependencies

  • ExcRestService
  • Created asset files (ALPHA-2) for each supported language ####Example
assets/i18n/GROOT/de.json
assets/i18n/de.json

Setup

Extend the following files

  1. app.module.ts Please be sure, that you inject ExcTranslateService after ExcRestService, because it depends on it.
//...
import {environment} from '../environments/environment';
import {ExcCoreModule} from 'exc-core-v2';
import {ExcRestModule, ExcRestService, ExcRestMode, ExcTranslateService} from 'exc-rest-v2';
import {AppComponent} from './app.component';

@NgModule({
  declarations: [AppComponent],
  imports: [
    BrowserModule,
    AppRoutingModule,
    ExcCoreModule,
    ExcRestModule
    //...
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule {
  constructor(private excRest: ExcRestService, private excTranslate: ExcTranslateService) {
    ExcCoreModule.RegisterConfig('Environment', environment);
    excRest.Mode = ExcRestMode.GROOT; /* GROOT is default-mode this line could be removed */
    excTranslate.activate(); /* Activation of ExcTranslateService */
  }
}
  1. app.component.ts
//...
import {ExcCoreModule, ExcTranslation} from 'exc-core-v2';
import {ExcRestService} from 'exc-rest-v2';

//...
export class AppComponent extends ExcTranslation implements OnInit {
//...
  constructor(private excRestService: ExcRestService) {
    super();
  }
}

Now you are able to use ExcTranslationService. It is automatically available in ExcTranslation class.

  1. Implementing Subscriber for language change
 export class AppComponent extends ExcTranslation implements OnInit {
//...
  constructor(private excRestService: ExcRestService) {
    super();
    this.onLangChange.subscribe(() => {
      // Do anything;
    });
  }
}
  1. Implementing language change
export class AppComponent extends ExcTranslation implements OnInit {
//...
  setLanguage(lang: string): void {
    ExcCoreModule.Services().TranslateService.setLanguage(lang).subscribe();
  }
}
1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago