title: How to use URI as a REST resource?
body: <p>I am building a RESTful API for retrieving and storing comments in threads. </p>
  
  <p>A comment thread is identified by an arbitrary URI -- usually this is the URL of the web page where the comment thread is related to. This design is very similar to what Disqus uses with their system.</p>
  
  <p>This way, on every web page, querying the related comment thread doesn't require storing any additional data at the client -- all that is needed is the canonical URL to the page in question.</p>
  
  <p>My current implementation attempts to make an URI work as a resource by encoding the URI as a string as follows:</p>
  
  <pre><code>/comments/https%3A%2F%2Fexample.org%2Ffoo%2F2345%3Ffoo%3Dbar%26baz%3Dxyz
  </code></pre>
  
  <p>However, before dispatching it to my application, the request URI always gets decoded by my server to </p>
  
  <pre><code>/comments/https://example.org/foo/2345?foo=bar&amp;baz=xyz
  </code></pre>
  
  <p>This isn't working because the decoded resource name now has path delimiters and a query string in it causing routing in my API to get confused (my routing configuration assumes the request path contains <code>/comments/</code> followed by a string).</p>
  
  <p>I could double-encode them or using some other encoding scheme than URI encode, but then that would add complexity to the clients, which I'm trying to avoid.</p>
  
  <p>I have two specific questions:</p>
  
  <ol>
  <li><p>Is my URI design something I should continue working with or is there a better (best?) practice for doing what I'm trying to do?</p></li>
  <li><p>I'm serving API requests with a Go process implemented using Martini 'microframework'. Is there something Go or Martini specific that I should do to make the URI-encoded resource names to stay encoded?
  Perhaps a way to hint to the routing subsystem that the resource name is not just a string but a URL-encoded string?</p></li>
  </ol>