File

src/modules/http/entities/http-parameter-codec.ts

Description

A custom implementation of Angular HttpParameterCodec to correctly encode/decode HTTP query parameters via the StarkHttpService.

Uses the default JavaScript method encodeURIComponent and decodeURIComponent for encoding and decoding.

See:

Implements

HttpParameterCodec

Index

Methods

Methods

Public decodeKey
decodeKey(key: string)

Decodes a key

Parameters :
Name Type Optional Description
key string No
  • Key to decode
Returns : string
Public decodeValue
decodeValue(value: string)

Decodes a value

Parameters :
Name Type Optional Description
value string No
  • Value to decode
Returns : string
Public encodeKey
encodeKey(key: string)

Encodes a key

Parameters :
Name Type Optional Description
key string No
  • Key to encode
Returns : string
Public encodeValue
encodeValue(value: string)

Encodes a value

Parameters :
Name Type Optional Description
value string No
  • Value to encode
Returns : string
import { HttpParameterCodec } from "@angular/common/http";

/**
 *
 * A custom implementation of Angular {@link https://v12.angular.io/api/common/http/HttpParameterCodec|HttpParameterCodec} to correctly
 * encode/decode HTTP query parameters via the {@link StarkHttpService}.
 *
 * Uses the default JavaScript method `encodeURIComponent` and `decodeURIComponent` for encoding and decoding.
 *
 * See:
 * - {@link https://github.com/NationalBankBelgium/stark/issues/1130}
 * - {@link https://github.com/angular/angular/issues/18261#issuecomment-426383787}
 */
export class StarkHttpParameterCodec implements HttpParameterCodec {
	/**
	 * Encodes a key
	 * @param key - Key to encode
	 */
	public encodeKey(key: string): string {
		return encodeURIComponent(key);
	}

	/**
	 * Encodes a value
	 * @param value - Value to encode
	 */
	public encodeValue(value: string): string {
		return encodeURIComponent(value);
	}

	/**
	 * Decodes a key
	 * @param key - Key to decode
	 */
	public decodeKey(key: string): string {
		return decodeURIComponent(key);
	}

	/**
	 * Decodes a value
	 * @param value - Value to decode
	 */
	public decodeValue(value: string): string {
		return decodeURIComponent(value);
	}
}

results matching ""

    No results matching ""