Angular 7处理大型帖子http请求 [英] Angular 7 Handling large post http request

查看:78
本文介绍了Angular 7处理大型帖子http请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有post http请求,该请求发送大量数据,并包含可能很大的数组.我正在尝试拆分请求,因此我想分块发送,而不是发送包含所有数据的一个请求.

I have post http request which sends large amount of data, and contains array which can be quite large. I am trying to split the request so instead sending one request which contains all of the data, I would like to send it in chunks.

// service.ts
saveRequest(request: AutomationChecklist) {
  return this.http
    .post(this.url + this.saveRequestUrl, request, this.options)
    .map((response: Response) => {
      return response.json();
    });
}

// automationChecklist.ts
export class AutomationChecklist {
  siteInformation: siteInformation;
  orderInformation: OrderInformation;
  requestInformation: RequestInformation;
  contactInformation: ContactInformation;
  installations: Installation[]; // save this separately, this one can be quite large
  completedAutomation: number;
  progress: number;
}

什么是解决此请求的可能解决方案?我已经阅读了有关forkjoin rxjs的文章,但不确定是否适合这种情况?

what can be the possible solution to handle this request? I have read about forkjoin rxjs but not sure if it will be suitable for this situation?

推荐答案

如果要分隔安装,则可以使用 concatMapTo 运算符进行操作:

If you want to separate installations you can do it using the concatMapTo operator :

saveRequest(automations: AutomationChecklist, installations: Installation[]) {
  return this.http
    .post(this.url + this.saveRequestUrl, automations, this.options)
    .pipe(concatMapTo(this.http.post(this.url + /*installations save url*/, installations, this.options)))
    .map((response: Response) => {
      return response.json();
    });
}

此解决方案的缺点:

  1. 针对相同要求的两个单独请求(创建一个新的后端端点)
  2. 不是原子的:安装请求可能会失败,但第一个请求会成功(可能导致不一致的结果)
  3. 安装请求等待第一个终止

这取决于您要执行的操作,如果您接受不一致的情况,这可能是减轻请求的好方法.

It depends on what you want to do, if you accept inconcistency, it could be a good solution to lighten your request.

这篇关于Angular 7处理大型帖子http请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆