node.js - Serialize query parameters to a filename -
i'd map api request 1::1 file name.
this means, among other things, serializing query params safe filename, ideally on both windows , *nix.
if api request this:
api/eggs/fresh?search=brown&order=asc   then filename might be:
api/eggs/fresh?search=brown&order=asc.json   but ? char , maybe & unsafe, have encode them think.
the serialization must bi-directionally deterministic. have able data out. converting illegal characters _, example, wouldn't meet criteria.
is right method querystring.encode? encoding urls might work if % file system safe. how url encode in node.js?? or there better suited file system?
i'm following process:
- get folder + resource name
 - get array of params in request
 - alphabetize params (so order doesn't matter)
 - join params 
&(i think safe in modern file systems) - concat 
folder/resource+__&__+paramstring+.json 
this fails if uses __&__ part of actual query, think that's unlikely. not cleanest solution, i'd love better one!
Comments
Post a Comment