world.db.starter Sample - Build Your Own HTTP JSON API (w/ world.db incl. Countries / States / Cities / etc.)

82 views
Skip to first unread message

Gerald Bauer

unread,
Aug 31, 2017, 4:24:10 AM8/31/17
to openmundi
Hello,

I've updated the world.db web service starter sample [1]
that gets you started building your own HTTP JSON API using the world.db
(incl. continents / countries / states / cities /etc.).

What's news? The starter sample now uses the new webservice library [2]
(a simplified sinatra 2.0-style library for HTTP JSON APIs). Example:


class StarterApp < Webservice::Base

include WorldDb::Models # e.g. Continent, Country, State, City, etc.

get '/countries(.:format)?' do
Country.by_key.all
end

get '/cities(.:format)?' do
City.by_key.all
end

get '/tag/:slug(.:format)?' do # e.g. /tag/north_america.csv
Tag.find_by!( slug: params['slug'] ).countries
end

...
end


Enjoy. Cheers.

[1]: https://github.com/worlddb/world.db.starter
[2]: https://github.com/rubylibs/webservice
Reply all
Reply to author
Forward
0 new messages