Monday, August 12, 2013

Domai.nr

The domai.nr service is a handy way to find domains that make nice short URLs like debu.gs, nick.is, and craftstud.io.

I had a need awhile back to access this web service from a script and query a bunch of domains all at the same time, so I thought it would be nice to have a wrapper in Factor.

The domai.nr service has a JSON API for performing searches, that we can build URLs for:

: domainr-url ( query -- url )
    URL" http://domai.nr/api/json/search"
    swap "q" set-query-param ;

Each result has these fields that are returned:

TUPLE: result domain host path subdomain availability
register_url ;

It is pretty simple to map a JSON request to these result tuples:

: domainr ( query -- data )
    domainr-url http-get nip json> "results" of
    [ result from-slots ] map ;

Finally, we can perform a query and print the output nicely showing which domains or URLs are available:

: domainr. ( query -- )
    domainr [
        [ subdomain>> ] [ path>> ] [ availability>> ] tri
        "%s%s - %s\n" printf
    ] each ;

Running this query for "factorcode" looks like:

IN: scratchpad "factorcode" domainr.
factorcode.com - available
factorcode.net - available
factorcode.org - taken
factorcode.co - available
factor.co/de - taken
factorcode.io - available
factorco.de - available
factorc.de - available
fac.to/rcode - available
f.actor/code - unavailable
f.ac/torcode - unavailable
fctrc.de - available
fctr.cd/e - available
fc.tr/cde - unavailable

Well, if we wanted to make our URL something like factorco.de we could, but I'm not sure that's worth it. Still, a neat way to look for interesting URLs and available on my GitHub.

2 comments:

Unknown said...

Seeing all the api's you implemented for factor, my question could already be answered.
I wondered if there is a vocab for nutrition api (from the web) for factor.

so I can request "kale" (100g) and get:
H{
{ "calories" 28 } ! kcal
{ "fat" 0.4 } ! g
{ "sodium" 23 } ! mg
{ "potasium" 228 } ! mg
{ "carbohydrate" 5.63 } ! g
{ "dietary fiber" 2 } ! g
{ "protein" 1.9 } ! g
{ "sugar" 1.25 } ! g
{ "water" 91.2 } ! g
! vitamins ...
} ...

What do you think?
thanks, kobi

mrjbq7 said...

I'm not aware of any written in Factor, but thats a good idea for another blog post!

The USDA Nutrition Database could be a useful source of nutrition data for such a thing. I started the process of parsing the data files this morning, maybe I can put together a working example in the next few days...