Wondering what’s next for npm?Check out our public roadmap! »

This package has been deprecated

Author message:

Development of this module has been stopped.

cache-url-normaliser

0.0.1 • Public • Published

cache url normaliser

Express middleware to populate a res.cache object with consistent URL parsing for use in cache keys.

Motivation

This simple middleware module provides an extra layer of URL parsing to provide an object useful for setting/getting cache keys within the request/response cycle. It normalises query string objects and provides suitable base and path strings. The resulting object is useful for finer granular cache keys in the context of an API server.

Output res.cache

For a/b/c/endpoint?c=12&order=asc&y=some_value&a=1&z=67:

{
  "pathname": "/a/b/c",
  "basename": "endpoint",
  "path": [
    "a",
    "b",
    "c"
  ],
  "base": "endpoint?a=1&c=12&order=asc&y=some_value&z=67"
}

Query Strings

For example all of the following:

  • endpoint?a=1&z=67&c=12&y=some_value&order=asc
  • endpoint?a=1&z=67&c=12&order=asc&y=some_value
  • endpoint?c=12&order=asc&y=some_value&a=1&z=67

...resolve to:

endpoint?a=1&c=12&order=asc&y=some_value&z=67

Example Use (with Redis HSET/HGET/HDEL)

For example in the sample res.cache above, we could use the concatenation of pathname (/a/b/c) and basename (endpoint) as the key, base (endpoint?a=1&c=12&order=asc&y=some_value&z=67) as the field and the data response from whatever data source as the value....

TO DO

Caveats

Nested properties (using [, ]), e.g. /shoes?order=desc&shoe[color]=blue&shoe[type]=converse as described here won't be parsed correctly.

License

MIT

Install

npm i cache-url-normaliser

DownloadsWeekly Downloads

0

Version

0.0.1

License

MIT

Last publish

Collaborators

  • avatar