I'd like to map an API request 1::1 with a file name.
This means, among other things, serializing query params into something safe for a filename, ideally on both Windows and *nix.
If the api request is this:
api/eggs/fresh?search=brown&order=asc
Then the filename might be:
api/eggs/fresh?search=brown&order=asc.json
But the ?
char and maybe the &
are unsafe, so I have to encode them I think.
The serialization must be bi-directionally deterministic. I have to be able to get the data back out. Converting all illegal characters to _
, for example, wouldn't meet this criteria.
Is the right method querystring.encode
? This is for encoding URLs but might work if %
is file system safe. How do I URl encode something in Node.js?? Or is there something better suited to a file system?