-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MNES-1070 Implement Submodel Registry Api Client
- Loading branch information
Showing
4 changed files
with
130 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
src/lib/api/submodel-registry-service/submodelRegistryServiceApi.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
import { SubmodelDescriptor } from 'lib/types/registryServiceTypes'; | ||
import { encodeBase64 } from 'lib/util/Base64Util'; | ||
|
||
export class SubmodelRegistryServiceApi { | ||
baseUrl: string; | ||
|
||
constructor(protected _baseUrl: string = '') { | ||
this.baseUrl = _baseUrl; | ||
} | ||
|
||
public async getSubmodelDescriptorsById(submodelId: string) { | ||
const b64_submodelId = encodeBase64(submodelId); | ||
|
||
const headers = { | ||
Accept: 'application/json', | ||
}; | ||
|
||
const url = new URL(`${this.baseUrl}/submodel-descriptors/${b64_submodelId}`); | ||
|
||
const response = await fetch(url, { | ||
method: 'GET', | ||
headers, | ||
}); | ||
|
||
if (response.ok) { | ||
return response.json(); | ||
} else { | ||
throw response; | ||
} | ||
} | ||
|
||
public async putSubmodelDescriptorsById(submodelId: string, submodelDescriptor: SubmodelDescriptor) { | ||
const b64_submodelId = encodeBase64(submodelId); | ||
|
||
const headers = { | ||
Accept: 'application/json', | ||
'Content-Type': 'application/json', | ||
}; | ||
|
||
const url = new URL(`${this.baseUrl}/submodel-descriptors/${b64_submodelId}`); | ||
|
||
const response = await fetch(url, { | ||
method: 'PUT', | ||
headers, | ||
body: JSON.stringify(submodelDescriptor), | ||
}); | ||
|
||
if (response.ok) { | ||
return response.json(); | ||
} else { | ||
throw response; | ||
} | ||
} | ||
|
||
public async deleteSubmodelDescriptorsById(submodelId: string) { | ||
const b64_submodelId = encodeBase64(submodelId); | ||
|
||
const url = new URL(`${this.baseUrl}/submodel-descriptors/${b64_submodelId}`); | ||
|
||
const response = await fetch(url, { | ||
method: 'DELETE', | ||
}); | ||
|
||
if (response.ok) { | ||
return response; | ||
} else { | ||
throw response; | ||
} | ||
} | ||
|
||
public async getAllSubmodelDescriptors() { | ||
const headers = { | ||
Accept: 'application/json', | ||
}; | ||
|
||
const url = new URL(`${this.baseUrl}/submodel-descriptors`); | ||
|
||
const response = await fetch(url, { | ||
method: 'GET', | ||
headers, | ||
}); | ||
|
||
if (response.ok) { | ||
return response.json(); | ||
} else { | ||
throw response; | ||
} | ||
} | ||
|
||
public async postSubmodelDescriptor(submodelDescriptor: SubmodelDescriptor) { | ||
const headers = { | ||
Accept: 'application/json', | ||
'Content-Type': 'application/json', | ||
}; | ||
|
||
const url = new URL(`${this.baseUrl}/submodel-descriptors`); | ||
|
||
const response = await fetch(url, { | ||
method: 'POST', | ||
headers, | ||
body: JSON.stringify(submodelDescriptor), | ||
}); | ||
|
||
if (response.ok) { | ||
return response.json(); | ||
} else { | ||
throw response; | ||
} | ||
} | ||
|
||
public async deleteAllSubmodelDescriptors() { | ||
const url = new URL(`${this.baseUrl}/submodel-descriptors`); | ||
|
||
const response = await fetch(url, { | ||
method: 'DELETE', | ||
}); | ||
|
||
if (response.ok) { | ||
return response; | ||
} else { | ||
throw response; | ||
} | ||
} | ||
|
||
} |