Angular's RouterModule knows how to deal with requests containing them
It sort of knows how to deal with them because this is a side effect of supporting multiple active routes.
Further down in the documentation it talks about named outlets:
https://angular.io/guide/router#displaying-multiple-routes-in-named-outlets
Basically, it's possible for the router to activate one or more routes at the same time. Which is impossible for a URL so the work around is to inject the named routes as encoded into the URL path.
So a named outlet might be activated with the following URL:
http://.../crisis-center(popup:compose)
The above takes advantage of the characters (:)
being valid URL characters. It's the same side effects we use to create matrix parameters, and you can see that the Angular team deliberately avoided collision with matrix parameters by using a different syntax.
I was wondering if Angular's HttpClient supports them (with URL-encoded values) in a way similar to how it supports query parameters with HttpParams?
The URL specification states that there can be only one query parameter.
That is not true for matrix parameters.
http://example.com/a;first=1/b;second=2/c;third=3
The above example shows that there are three distinct sets of matrix parameters. The web server would read these as follows:
a?first=1
b?second=2
c?third=3
There is a tight coupling between the URL path and parameters. Since the URL is a single parameter for the HttpClient methods. It's not possible (without changing the API) to pass matrix parameters separately.
Put differently, Angular seems to deal with URL-encoding and adding question mark, equal signs and ampersands for query params - can it do the equivalent for matrix params?
I'm sure you could create an API of some kind that would encode matrix parameters, but it would be at the URL level. Which means that the URL string would be a procedural value making the API less user friendly.
There are also multiple patterns for using matrix parameters. Java, C#, Python, etc.. etc.. all have frameworks that do them differently.
What's the clean/Angular way of using matrix parameters in requests
There isn't one. It's just another URL string.
(and will URL encoding of the matrix parameter values be taken care of automagically by HttpClient and its dependencies or is that something the dev has to do explicitly)?
You can not encode a URL and the HttpClient
receives the URL as the first parameter. Here is an example of what happens.
console.log(encodeURIComponent('https://www.example.com/'));
Since a matrix parameter is part of the URL (before the query) then it's up to you to create a valid URL.
So basically, to answer your question. You need your own utility to generate the URL before you call HttpClient.get()
function encodeMatrix(url: string, params: any) {
// do work
return url;
}
httpClient.get(encodeMatrix("https://www.example.com/", myParams)).subscribe()