-
Notifications
You must be signed in to change notification settings - Fork 107
Description
Originally posted by @webbnh in #2024 (comment)
Would it be more useful to report the template string with JS template arguments in it? E.g.,
param_template = re.compile(r"<(?P<type_name>\w+):(?P<param_name>\w+)>")
[...]
url = self.param_template.sub("${\g<param_name>}", url)
such that "/api/v1/foo/<string:name>/detail/<string:param>" would be reported as ".../api/v1/foo/${name}/detail/${param}".
The client has to remove/substitute the templates then and I figured that wasn't very generic. I didn't really want to make it so Javascript-specific, either, and Javascript will only do that sort of substitution in literal template strings (backticked), so far as I can tell; although it's just a .replace away, it's not quite that neat.
Anyway, just letting it append the username to the end of the URI seemed easiest, at least for now.
I guess I was proposing two things:
- make the URI available as a template
- make it easy for the client to fill in the template (which is why I offered JS syntax)
It doesn't have to be Javascript format, but I'll point out that that format also works for shell, so it's not exactly JS-specific. ;-) We could use %s instead of ${...}, but I opted for the latter because it provides semantic information.
It's true that the client will likely need to have some foreknowledge in order to fill in the template, but it will need to have even closer coupling to produce the URI if we just lop it off at the first parameter. Providing a template removes the need for some of that coupling.
Apparently there is a (proposed) IETF standard for URI templates.