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:

  1. get folder + resource name
  2. get array of params in request
  3. alphabetize params (so order doesn't matter)
  4. join params & (i think safe in modern file systems)
  5. 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

Popular posts from this blog

How can we post XML strings along with text strings in iOS -

How to run C# code using mono without Xamarin in Android? -

c# - cefsharp app remember password option -