is google translate api v2 a RESTful architeture?
Google translate API v2 is pure GET style and they only have one url (or one resource) at https://www.googleapis.com/language/translate/v2
so basically all variants of the tool will be called like this https://www.googleapis.com/language/translate/v2?parameters
开发者_C百科They claim that service to be RESTful (http://code.google.com/apis/language/translate/v2/using_rest.html) because it is based on a simple GET url.
But strictly speaking is it actually a RESTful architecture?
Because having a service based on a simple GET url is not analogous to being RESTful right?
I personally will expose any service as REST only if I can model the service as resource oriented which in most cases is about exposing data as resources. In case of google translate API, it gives more of an RPC feel rather than a resource that it is exposing. Hence even though google may call it REST based (as it is based on simple GET URL), I would not consider it as a REST based service. Also if you look at the URL, it is not identifying a resource, rather it looks more like a endpoint to which you pass values in query string and based on those values you get the result.
If you want to call it RESTful it should meet Fielding's criteria
Client-Server — separates UI from data storage
Stateless Server — improves reliability and scalability
Client Cache — reduces some network traffic
Uniform Interface — decouples implementations from the services they provide
Layered System — means that each component only be concerned with those just below or just above it
Code-on-Demand — allows client functionality to be extended by downloading applets or scripts
Also it should have addressable resources, representation orientation, self-descriptive messages, stateless server, and cacheability.
So what if API is just a GET call with multiple parameters? The question is: Is the GET (with parameters) idempotent and safe? Well I think so. It's a "read-only" interface. You never change the state on the server. So the GET is safe and idempotent and cacheable for given query params.
That is RESTful to me.
Now when people use GET to post stuff.... that's where you should object.
精彩评论