@angular/common/http#HttpProgressEvent TypeScript Examples

The following examples show how to use @angular/common/http#HttpProgressEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: rest-v2.structure.ts    From App with MIT License 6 votes vote down vote up
CreateEmote(data: FormData): Observable<HttpProgressEvent | HttpResponse<DataStructure.Emote>> {
		return this.restService.createRequest('post', '/emotes', {
			body: data,
			auth: true,
			headers: {
				'ngsw-bypass': ''
			}
		}, 'v2');
	}
Example #2
Source File: rest.service.ts    From App with MIT License 6 votes vote down vote up
// tslint:enable:typedef

	createRequest<T>(
		method: RestService.Method,
		route: string,
		options?: Partial<RestService.CreateRequestOptions>,
		apiVersion: RestService.ApiVersion = 'v2'
	): Observable<HttpResponse<T> | HttpProgressEvent> {
		if (this.platformId === 'server' && !options?.runOnSSR) {
			return EMPTY;
		}

		const uri = (route.startsWith('http') ? '' : this.BASE[apiVersion]) + route;
		const opt = {
			observe: 'events',
			headers: {
				...(options?.headers ?? {}),
				Authorization: (options?.auth && this.clientService.getToken()?.length > 0) ? `Bearer ${this.clientService.getToken()}` : ''
			},
			reportProgress: true
		} as any;

		return of(method).pipe(
			switchMap(m => iif(() => (m === 'get') || (m === 'delete'),
				this.httpService[m](uri, opt),
				this.httpService[m as RestService.BodyMethod](uri, options?.body ?? {}, opt)
			))
		).pipe(map((x: any) => x as (HttpResponse<T> | HttpProgressEvent)));
	}
Example #3
Source File: http.ts    From ngx-operators with MIT License 5 votes vote down vote up
export function isHttpProgressEvent(
  event: HttpEvent<unknown>
): event is HttpProgressEvent {
  return (
    event.type === HttpEventType.DownloadProgress ||
    event.type === HttpEventType.UploadProgress
  );
}