README
@advsol/core
This library is intended for Angular version > 9.0.2.
It will handle authentication for all your HTTP requests to the iMIS API from Angular based iParts, automatically adding on the RequestVerificationToken, from the DOM and correctly setting the path for your HTTP requests.
Install
npm install @advsol/core
Use
Add AsiCoreModule to your imports
. This will enable the interceptor, which will add the RequestVerificationToken
header to all of your HttpClient requests.
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { AsiCoreModule } from '@advsol/core';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
AsiCoreModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
Example
import { Component } from '@angular/core';
import { HttpClient, HttpParams } from '@angular/common/http';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = ' iMIS!';
constructor(private http: HttpClient) {}
// Get Settings for the current iPart
example(): void{
const ck = (document.querySelector("#x-contentKey") as HTMLInputElement).value;
const cik = (document.querySelector("#x-contentItemKey") as HTMLInputElement).value;
const params = new HttpParams()
.set('contentKey', ck)
.set('contentItemKey',cik);
this.http.get("api/ContentItem",{params: params}).subscribe((data) => {
console.log(data);
});
}
}
Helper Service
The CommonService
class can simplify calling the iMIS API even further. It is able to determine the correct API resource from your data contract and also removes the paging JSON from the data.
Example
Create your model
import {DataContract} from '@advsol/core';
export class ContentItemData extends DataContract {
$type = 'Asi.Soa.Core.DataContracts.ContentItemData, Asi.Contracts';
Data: Data;
}
interface Data {
ContentKey: string;
ContentTypeKey: string;
...
Using your model in a service
When using the CommonService
@advsol/core
will automatically determine the correct API resource from your model.
@Injectable({
providedIn: 'root'
})
export class IpartSettingsService extends CommonService {
constructor(private http: HttpClient, private contentKeys: ContentKeysService) {
super(http);
}
public GetSettings (): Observable<ContentItemData>
{
const params = new HttpParams()
.set('contentKey', this.contentKeys.contentKey)
.set('contentItemKey',this.contentKeys.contentItemKey);
return this.single(ContentItemData,params);
}
}
Methods
single
find
add
update
execute
delete
The sample project here shows how to use this package.