Could examples API be changed to return a URL even if no examples?

8 views
Skip to first unread message

Andy Fingerhut

unread,
Feb 25, 2011, 2:36:23 PM2/25/11
to ClojureDocs.org Discussion Group
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=&gt; (min 1 2 3 4 5) \\r\\n1\\r\\nuser=&gt; (min 5 4 3 2 1)\\r\
\n1\\r\\nuser=&gt; (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

Lee Hinman

unread,
Feb 25, 2011, 3:52:00 PM2/25/11
to clojure...@googlegroups.com

On Friday, February 25, 2011 at 12:36 PM, Andy Fingerhut wrote:

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
I can probably wrangle something up for this on the API side, open an issue on https://github.com/dakrone/cd-wsapi to remind be about it and I'll work on it.

- Lee
Reply all
Reply to author
Forward
0 new messages