-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(module-http): add functionality for blob query
- Loading branch information
Showing
5 changed files
with
66 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
'@equinor/fusion-framework-module-http': minor | ||
--- | ||
|
||
add method for executing blob requests | ||
|
||
- added selector for extracting blob from response | ||
- added function for fetching blob as stream or promise on the http client | ||
|
||
|
||
```tsx | ||
const data = await client.blob('/person/photo'); | ||
const url = URL.createObjectURL(blob); | ||
return <img src={url} /> | ||
``` |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
export const blobSelector = <TResponse extends Response = Response>( | ||
response: TResponse, | ||
): Promise<Blob> => { | ||
if (!response.ok) { | ||
throw new Error('network response was not OK'); | ||
} | ||
//Status code 204 is no content | ||
if (response.status === 204) { | ||
throw new Error('no content'); | ||
} | ||
|
||
try { | ||
return response.blob(); | ||
} catch (err) { | ||
throw Error('failed to parse response'); | ||
} | ||
}; | ||
|
||
export default blobSelector; |
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
export { jsonSelector } from './json-selector'; | ||
export { blobSelector } from './blob-selector'; |