News for hackers. Stuff that matters.
Re:Get information about any country via a RESTful API by masklinn on Thursday October 31, 2013 @09:13AM (#6646564)
Obligatory warning: API is absolutely not restful.
Re:Get information about any country via a RESTful API by smizell on Thursday October 31, 2013 @09:53AM (#6646775)
Just wanted to add some thoughts on how one could try to make this RESTful. First, if it were me, I'd pick a media type that can express hyperlinks in JSON (since JSON knows nothing about hyperlinks), maybe something like HAL [1]. Next, I would define my link relations for this API, which in this case would be a collection of countries and the countries themselves (so at least two different types of resources).

After creating the representations of each of these resources, I would then create URI templates in my root response (I guess found at /rest) that allow for the searching aspect that this site is providing, which would be something like:

  { 
    "_links": {
      "search_by_name": {
        "href": "/rest/name/{name}",
        "templated": true
      }
    }
  }
I may build on to this to provide other resources, like a collection of capitals, each with a link to "/rest/capital/{capital_city}", or a resource of currencies, linking to "/rest/currency/{currency}".

The goal of all of this would be to tell the client how to find resources rather than having that hard-coded into the client. These are just some first steps toward being RESTful, and there are lots of different directions you could take this and still be RESTful.

edit: example was incomplete

[1] http://stateless.co/hal_specification.html

Re:Get information about any country via a RESTful API by vaeke on Friday November 01, 2013 @08:37AM (#6653255)
thanks for your input. i'll think about this
Re:Get information about any country via a RESTful API by cognivore on Thursday October 31, 2013 @09:39AM (#6646697)
Since the project seems to have an educational bent, what would the proper REST interface for it look like?

GET:

http://restcountries.eu/rest/alpha/ee would be http://restcountries.eu/countries?alpha=ee

http://restcountries.eu/rest/name/norge would be http://restcountries.eu/countries?name=norge

That seems right, right?

Re:Get information about any country via a RESTful API by smizell on Thursday October 31, 2013 @10:05AM (#6646826)
Neither is more or less RESTful than the other. The media type and link relations express to the client what resource is being returned, not the URL itself.
Re:Get information about any country via a RESTful API by ddoolin on Thursday October 31, 2013 @09:36AM (#6646680)
But it even has "rest" in the URL! You mean that doesn't make it RESTful (rest-full?)