File

src/modules/http/serializer/http-serializer.intf.ts

Description

This is the base interface for entities' serializers used mainly by the StarkHttpService.

It is a generic interface defined by these types:

  • ResourceType: type that this serializer handles.
  • RequestType: defaults to StarkHttpRequest
  • ResponseType: defaults to the Angular HttpResponse

Index

Methods

Methods

deserialize
deserialize(raw: string | object, request?: RequestType, response?: ResponseType)

Deserialize provided string or object into the corresponding resource entity

Parameters :
Name Type Optional Description
raw string | object No
  • The raw format to deserialize from
request RequestType Yes
  • Optional request object
response ResponseType Yes
  • Optional response object
Returns : ResourceType

The entity instance created out of the deserialization process.

serialize
serialize(resource: ResourceType, request?: RequestType)

Serialize the given resource entity into an object or a string

Parameters :
Name Type Optional Description
resource ResourceType No
  • The entity to serialize
request RequestType Yes
  • Optional request object
Returns : string | object

The serialized form of the provided resource

import { HttpResponse } from "@angular/common/http";
import { StarkHttpRawCollectionResponseData, StarkHttpRequest, StarkResource } from "../entities";

/**
 * This is the base interface for entities' serializers used mainly by the {@link StarkHttpService}.
 *
 * It is a generic interface defined by these types:
 * - `ResourceType`: type that this serializer handles.
 * - `RequestType`: defaults to {@link StarkHttpRequest}
 * - `ResponseType`: defaults to the Angular {@link https://v12.angular.io/api/common/http/HttpResponse|HttpResponse}
 */
export interface StarkHttpSerializer<
	ResourceType extends StarkResource,
	RequestType = StarkHttpRequest,
	ResponseType = HttpResponse<ResourceType | StarkHttpRawCollectionResponseData<ResourceType>>
> {
	/**
	 * Serialize the given resource entity into an object or a string
	 *
	 * @param resource - The entity to serialize
	 * @param request - Optional request object
	 *
	 * @returns The serialized form of the provided resource
	 */
	serialize(resource: ResourceType, request?: RequestType): string | object;

	/**
	 * Deserialize provided string or object into the corresponding resource entity
	 *
	 * @param raw - The raw format to deserialize from
	 * @param request - Optional request object
	 * @param response - Optional response object
	 *
	 * @returns The entity instance created out of the deserialization process.
	 */
	deserialize(raw: string | object, request?: RequestType, response?: ResponseType): ResourceType;
}

results matching ""

    No results matching ""