While working on my Angular/TypeScript project, I encountered a challenge in processing a GET request to retrieve objects from an integration account. Here is a snippet of the response data:
{
"value": [
{
"properties": {
"publicCertificate": "<publicCertificate>",
"createdTime": "2021-03-11T19:50:03.50193Z",
"changedTime": "2021-03-26T07:06:12.3232003Z"
},
"id": "/subscriptions/34adfa4f-cedf-4dc0-ba29-b6d1a69ab345/resourceGroups/testResourceGroup/providers/Microsoft.Logic/integrationAccounts/testIntegrationAccount/certificates/<integrationAccountCertificateName>",
"name": "<integrationAccountCertificateName>",
"type": "Microsoft.Logic/integrationAccounts/certificates"
},
{
"properties": {
"publicCertificate": "<publicCertificate>",
"createdTime": "2021-05-27T12:45:33.455709Z",
"changedTime": "2021-05-27T12:45:33.4564322Z"
},
"id": "/subscriptions/34adfa4f-cedf-4dc0-ba29-b6d1a69ab345/resourceGroups/testResourceGroup/providers/Microsoft.Logic/integrationAccounts/testIntegrationAccount/certificates/<integrationAccountCertificateName>",
"name": "<integrationAccountCertificateName>",
"type": "Microsoft.Logic/integrationAccounts/certificates"
}
]
}
I am currently using the following interface structure:
export interface Certificate {
value?: (ValueEntity)[] | null;
}
export interface ValueEntity {
properties: Properties;
id: string;
name: string;
type: string;
}
export interface Properties {
publicCertificate: string;
createdTime: string;
changedTime: string;
}
My goal is to extract and display the publicCertificate
, id
, name
, and type
values from the response data. Is there a more streamlined way to define this interface?
EDIT
Below is the service I have implemented for fetching the certificates:
@Injectable()
export class IntegrationAccountService
{
constructor(private httpclient: HttpClient, private api: ApiService) { }
getCertificates(): Observable<any> {
const httpOptions : Object = {
headers: new HttpHeaders({
'Authorization': 'Token'
}),
responseType: 'json'
};
return this.httpclient.get('URL', httpOptions);
}
}
Component:
export class CertificateTableComponent {
dataSource: MatTableDataSource<ValueEntity>;
certificates: ValueEntity[] = [];
columns: string[] = ['name', 'id', 'type', 'publicCertificate'];
@ViewChild(MatSort, { static: true }) sort: MatSort;
@ViewChild(MatPaginator, { static:true }) paginator: MatPaginator;
constructor(private _integrationAccountService: IntegrationAccountService) {
}
ngOnInit() {
this._integrationAccountService.getCertificates().subscribe(response => {
this.certificates = response.data;
this.dataSource = new MatTableDataSource(this.certificates);
this.dataSource.sort = this.sort;
this.dataSource.paginator = this.paginator;
})
}
}
Data table Component:
<table mat-table [dataSource]="dataSource" matSort>
<ng-container matColumnDef="name">
<th mat-header-cell *matHeaderCellDef mat-sort-header>Name</th>
<td mat-cell *matCellDef="let row">{{ row.name }}</td>
</ng-container>
<ng-container matColumnDef="id">
<th mat-header-cell *matHeaderCellDef mat-sort-header>Id</th>
<td mat-cell *matCellDef="let row">{{ row.id }}</td>
</ng-container>
<ng-container matColumnDef="type">
<th mat-header-cell *matHeaderCellDef mat-sort-header>Type</th>
<td mat-cell *matCellDef="let row">{{ row.type }}</td>
</ng-container>
<ng-container matColumnDef="publicCertificate">
<th mat-header-cell *matHeaderCellDef mat-sort-header>Public Certificate</th>
<td mat-cell *matCellDef="let row">{{ row.publicCertificate }}</td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="columns"></tr>
<tr mat-row *matRowDef="let row; columns: columns;"></tr>
</table>