MCPcopy Index your code
hub / github.com/angular/angular / serializeBody

Method serializeBody

packages/common/http/src/request.ts:442–472  ·  view source on GitHub ↗

* Transform the free-form body into a serialized format suitable for * transmission to the server.

()

Source from the content-addressed store, hash-verified

440 * transmission to the server.
441 */
442 serializeBody(): ArrayBuffer | Blob | FormData | URLSearchParams | string | null {
443 // If no body is present, no need to serialize it.
444 if (this.body === null) {
445 return null;
446 }
447 // Check whether the body is already in a serialized form. If so,
448 // it can just be returned directly.
449 if (
450 typeof this.body === 'string' ||
451 isArrayBuffer(this.body) ||
452 isBlob(this.body) ||
453 isFormData(this.body) ||
454 isUrlSearchParams(this.body)
455 ) {
456 return this.body;
457 }
458 // Check whether the body is an instance of HttpUrlEncodedParams.
459 if (this.body instanceof HttpParams) {
460 return this.body.toString();
461 }
462 // Check whether the body is an object or array, and serialize with JSON if so.
463 if (
464 typeof this.body === 'object' ||
465 typeof this.body === 'boolean' ||
466 Array.isArray(this.body)
467 ) {
468 return JSON.stringify(this.body);
469 }
470 // Fall back on toString() for everything else.
471 return (this.body as any).toString();
472 }
473
474 /**
475 * Examine the body and attempt to infer an appropriate MIME type

Callers 4

request_spec.tsFile · 0.80
handleMethod · 0.80
makeCacheKeyFunction · 0.80
createRequestInitMethod · 0.80

Calls 6

isArrayBufferFunction · 0.85
isBlobFunction · 0.85
isFormDataFunction · 0.85
isUrlSearchParamsFunction · 0.85
isArrayMethod · 0.80
toStringMethod · 0.65

Tested by

no test coverage detected