Paramethers with '/' in ExpressJS - angularjs

I was wondering how to make a GET call passing a param that contains the '/' character. Is it possible?
Example: GET /service/products/GIANAX W/22 cps
Thank you all very much!

Use encodeURIComponent on the piece of the URL that contains the / and use the resulting string as your actual URL.
For example, if you call encodeURIComponent() on "GIANAX W/22 cps" and combine it back with the other part of the URL, you will get:
/service/products/GIANAX%20W%2F22%20cps
Note, you can only call encodeURIComponent on one path segment at a time. You can't call it on the whole URL or otherwise it will escape the actual path separators that you want to retain.

Related

LogicApp Split and Replace having problems with \n

I have been trying to split a string into an array of each line \n
As this doesn't work I tried replacing replace(outputs('Compose_6'),'\r\n','#') with a view to then splitting on #.
I have searched the internet and tried various things but nothing seems to work.
Can someone explain how to do this?
Thanks in advance
Using split(variables('string var'),'\n') expression, you can split string into array. By default logic app will add an extra black slash to original back slash. So suggesting you to change expression in code view as mentioned above.
I have created logic app as shown below,
In first initialize variable action, taken a string variable with text as shown below
Hello
Test split functionality
Using logic apps
Next initialize variable action, using a array variable and assigning value using expression as split(variables('string var'),'\n'). Make sure you dont have double back slash added in code view. Only one back slash should be there when you see it in code view.
Code view:
The output of logic app can be shown below,
Refer this SO thread.

What encoding function does useSearchParams() use?

I am writing a wrapper around react-router's useSearchParams() hook that automatically handles the (de)serialization of individual search parameters. In my unit test I am attempting to verify that calling the update function returned from the useSearchParams() function will also update the location's search property properly (handling any encoding automatically).
My unit test is nearly working, but the final check is failing. I am expecting the updated value to be $%{ }#=! - and when I use encodeURIComponent on it it becomes: "%24%25%7B %20 %7D%23%3D !"
However, the value that I get back for the parameter from useLocation()'s search property is "%24%25%7B + %7D%23%3D %21"
(white space added so I can bold things for emphasis)
While very similar, and clearly the same value when decoded, react-router is encoding certain characters ever so slightly differently from the standard encodeURIComponent function. Here we see that the whitespace character is getting encoded as %20 by encodeURIComponent and as + by react-router. The exclamation mark is being left simply as ! by encodeURIComponent while react-router has encoded it as %21
Is there a standard function somewhere that will allow me to use and test against react-router's encoding? Or is there any documentation describing the differences between react-router's encoding vs the standard encodeURIComponent function so that I might write my own?
Thanks!

API Gateway pass array of parameters in querystring

I have some issues with passing array of parameters to query string for GET method, for example, /resource&item=1&item=2&item=3.
I have tried to pass parameters separated by commas and by &, it doesn`t work. How to configure API Gateway to do this? Can anyone help me?
Your example was using an ampersand (&) instead of a question mark (?) for separating the query string parameter from the path. I'm assuming that's just a typo.
Try passing the array using json syntax like
/resource?item=['1','2','3']
have you tried this way :
/resource&item[]=1&item[]=2&item[]=3
The way you used would erase the first data by the last data in the url.
What we are doing in our company is to pass data separated by ,. On Backend we explode the parameter and make it array again. I am not sure if there is more better way to do it or not. Let me know if you find any.
like ?items=1,2,3,4
And we get explode items with , through extra code
and get result as [1,2,3,4]

AugluarJS truncating trailing equal sign

AngularJS truncates the trailing equal signs when routing to them. I have a base64 string which need to be added as a query parameter to the url(route)
ex: http://example.com/#!/updatepassword?code=NnuW3q49QW38Mf-Cg==
this loads as:
http://example.com/#!/updatepassword?code=NnuW3q49QW38Mf-Cg
Is there a workaround for this?
If you try to set route as a string, then you need to escape = sign. That's because this character has a special meaning in the query string - it separates parameter name from its value.
So, one solution could be:
var query = "code=NnuW3q49QW38Mf-Cg==";
$location.url("/some/path?" + encodeURIComponent(query));
What encodeURIComponent() will do, is it will replace all special characters - = will be replaced with %3D for instance. This will prevent it from being interpreted as a key-value separator.
If you only want to change the query string parameters, not the whole URL, you can also use $location.search() method:
$location.search("code", "NnuW3q49QW38Mf-Cg==");
Just remember to pass two parameters to that method, not one. If you do:
$location.search("code=NnuW3q49QW38Mf-Cg==");
the = sign will not get escaped, only stripped.
Angular uses parseKeyValue() function internally to parse query string, it can be found here. You can see that the split is being done over the = sign. That's why they get stripped.
But if you take a look at .search() method implementation, you see that parseKeyValue() is being called only if you supply one argument to .search(). It's not invoked if you supply name of the parameter as a first, and value as a second argument.
Peeking at the source code also suggests yet another solution:
$location.search({"code": "NnuW3q49QW38Mf-Cg=="});

AngularJS: avoid url encoding with $location

I notice that when I passed a parameter that is an array to $location.search(), it was encoded as in the following example
$location.path('/somePath').search('ids[]=', [1, 2, 3]);
becomes
/somePath?ds%5B%5D=1&ds%5B%5D=2&ds%5B%5D=3
Is there a way to avoid the url encoding?
Excuse the late reply, but I struck a similar predicament myself and thought I'd offer advice.
In short, if you intend on using $location.search you cannot avoid the URL being encoded.
If you take a look at the Angular source, location.js specifically, you'll notice that the functions return composed URLs (i.e. LocationHtml5Url) all rely on another function call named toKeyValue, which will encode all key-value pairs whenever they are set.
Furthermore, in the example use case you've provided, you don't need the equals inside your key. When $location.search is called with two parameters, they are treated as a key-value pair by Angular.
If you need to make use of the location URL after it has been encoded, you could always call decodeURIComponent.
Some years late, but I have found a way to bypass the URI encode made by the $location service: just rewrite the window.encodeURIComponent
var original = window.encodeURIComponent;
window.encodeURIComponent = function (str) {
return decodeURI(str);
};
$location.url('/somePath?ids=[1,2,3]');
window.encodeURIComponent = original;
It is not the best solution, but it works as intended.

Resources