Why? Because then cd-client's browse-to function could use the
examples API to get the URL for a symbol, even if it currently has no
examples. Right now browse-to fails to browse to a web page for a
symbol if it has no examples.
I know that we _could_ modify browse-to to use the search API instead,
but then I suspect it makes the server do more work finding and
returning more results, and then the client needs to sift through them
for the one that it wants.
Example: Here is what is returned by the API for something that
currently has 0 examples:
user=> (require '[clj-http.client :as http])
nil
user=> (require '[cd-client.core :as c])
nil
user=> (http/get (str c/*examples-api* "clojure.core/re-groups"))
{:status 200, :headers {"date" "Fri, 25 Feb 2011 19:33:32 GMT",
"charset" "UTF-8", "content-type" "application/json", "content-length"
"4", "via" "1.1
api.clojuredocs.org", "connection" "close"}, :body
"null"}
As a contrast, here is what comes back for a symbol that has 1
example:
user=> (http/get (str c/*examples-api* "clojure.core/min"))
{:status 200, :headers {"date" "Fri, 25 Feb 2011 19:34:31 GMT",
"charset" "UTF-8", "content-type" "application/json", "content-length"
"382", "via" "1.1
api.clojuredocs.org", "connection" "close"}, :body
"{\"url\":\"
http://clojuredocs.org/v/2104\",\"examples\":
[{\"namespace_id\":99,\"ns\":\"clojure.core\",\"updated_at\":
\"2010-07-17 18:46:59.0\",\"function\":\"min\",\"version\":
2,\"created_at\":\"2010-07-17 18:46:59.0\",\"library\":\"Clojure Core
\",\"lib_version\":\"1.2.0\",\"library_id\":3,\"body\":\"<pre>\\r\
\nuser=> (min 1 2 3 4 5) \\r\\n1\\r\\nuser=> (min 5 4 3 2 1)\\r\
\n1\\r\\nuser=> (min 100)\\r\\n100\\r\\n</pre>\"}]}"}
Notice the URL
http://clojuredocs.org/v/2104 buried in there.
It would be nice if there were no examples that a non-empty body could
be returned with the correct URL for the symbol, plus an empty vector
for the examples, i.e. [].
Thanks,
Andy