Angular 7 Handling large post http request

Muhammad Ali

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;
}

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?

bubbles

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();
    });
}

Drawbacks of this solution:

  1. Two separate requests for the same requirement (create a new backend endpoint)
  2. Not atomic : the installations request may fail but the first one is succeeded (may lead to inconsist result)
  3. Installations request waits the first one to terminate

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related