Request and response map keyword namespacing

235 views
Skip to first unread message

Mark McGranaghan

unread,
Mar 3, 2010, 10:37:10 AM3/3/10
to Ring
Hi All,

The recent clj-oauth thread [1] prompted me to rethink namespacing of
keys in Ring request and response maps.

The Ring 0.1 spec [2] states:

If a component invokes another component with a request map
containing
additional keys, these keys must be namespaced using the Clojure
:name.space/key-name convention. The ring.* namespaces are reserved.
...
As with request maps, keys in response maps other than those listed
above should
be appropriately namespaced.

But we're already adding non-namespaced keys to the request and
response maps in the Ring libraries themselves, for example from the
params, cookies, and session middlewares.

My thinking at the time was that 0.2 would allow components in the
main Ring distribution to use non-namespaced keys, but that externally-
maintained components would still be required to use namespaced keys.

I'm now leaning towards not requiring namespacing at all. My reasons
are:

- As mentioned above, we're not namespacing our own keys.
- I don't see key conflicts as actually being a problem. This might
change as the Ring ecosystem grows, but I can't think of any specific
names for which I anticipate conflicts.
- It's inconvenient to use namespaced keys as functions:
(:some.deep.ns/key-name req) vs (:key-name req)
- It might actually create a naming problem as component
implementations move across repositories. For example, say a user
creates a "ring-utils" library with a "wrap-json-params" middleware
that adds the :ring-utils/json-params key to the request map. If we
eventually pull that component into ring-core or a ring-contrib, what
would the new key be? It would either have to change or be
inconsistent with the new enclosing library name, both of which would
be problematic. But if the original key was just :json-params we
wouldn't have this problem.

Does anyone feel strongly either way about the namespacing issue?

- Mark

[1] http://groups.google.com/group/ring-clojure/browse_thread/thread/6dc4fa43ff616432
[2] http://github.com/mmcgrana/ring/raw/5e7610920ee7df4e490eb9ae63bd26cf2593a146/SPEC

James Reeves

unread,
Mar 5, 2010, 8:00:02 AM3/5/10
to Ring
Namespaced keywords are a little clunky to use in Clojure, because you
can't require or use them. If you want to use a keyword from a library
namespace, you have to type out its namespace in full each time.

I'd imagine that if you wanted to add application specific data to the
request or response map, then namespacing the keyword might be a good
idea. But if you're developing a library (like wrap-json-params), then
you likely want generic keywords (:json-params and :params).

So I'm in favour of lifting this restriction.

- James

> [1]http://groups.google.com/group/ring-clojure/browse_thread/thread/6dc4...
> [2]http://github.com/mmcgrana/ring/raw/5e7610920ee7df4e490eb9ae63bd26cf2...

Reply all
Reply to author
Forward
0 new messages