1. HTTP methods are improperly used. The documentation states "All API calls should be sent as a GET HTTP request". GET is used to retrieve resources, and should be cacheable. It should NEVER change the state of a resource. Yet we see in that it's used to delete, create, and modify resources! Examples:
GET https://subdomain.sharefile.com/rest/folder.aspx?op=create...
GET https://subdomain.sharefile.com/rest/file.aspx?op=delete
These should be as follows:
POST https://subdomain.sharefile.com/rest/folder.aspx
DELETE https://subdomain.sharefile.com/rest/file.aspx
HTTP verbs have specific semantics that allow for intelligent, scalable architecture.
2. Individual resources are not identified by an unchangeable URI. Let's say I want a folder:
GET https://subdomain.sharefile.com/rest/folder.aspx?op=get&...
Nope. This is more RESTful:
GET https://subdomain.sharefile.com/rest/folder/123
Two things to note: 1) no 'aspx' bullshit, that's implementation and shouldn't be visible to the user, and 2) the ID is in the URI itself as opposed to the params. URIs should seldom, if ever, change. Parameter names may change, URIs shouldn't.
3. Violation of content type retrieval. Let's say I want a folder as XML:
GET https://subdomain.sharefile.com/rest/folder.aspx?op=get&...
Wrong. This is the request I should be sending as a curl:
curl https://subdomain.sharefile.com/rest/folder/123 -H 'Accept: text/xml'
Note that I'm using the Accept header. This allows for flexibility in accessing my resource. With any luck, the server will give me an XML file, and its content type should be "text/vnd.sharefile+xml" (vendor specific content types are best).
4. No link relations in the body. I'm mostly assuming this because I haven't seen sample response bodies, but almost no one does this even though is a crucial aspect of a RESTful service. RESTful services describe the relationship between resources. Suppose I have an ordered collection of files. When retrieving a file, it should describe its relationship in this ordered collection. This is done either via the LINK header, or some sort of scheme in your response body (e.g. JSON Schema describes 'link' attributes).
A pretty good RESTful API is Github's (see http://developer.github.com/). If you'd like to learn more, I highly recommend "REST in Practice" by Webber, et al (http://www.amazon.ca/REST-Practice-Hypermedia-Systems-Archit...).
http://roy.gbiv.com/untangled/2008/rest-apis-must-be-hyperte...
A semi-related question - this is something I've wondered for a while - does the XMLHttpRequest single origin policy actually do anything for security? What kind of malicious resource might you try to fetch with an ajax call that can't just be wrapped in a jsonp callback?
- Linked to that, a significant part of the documentation is about URLs to hit instead of being about document types
* Misuse of HTTP verbs, a lack of use (by going through POST for everything) would be bad enough but they go through GET which should be 1. safe (should not alter the server's visible state) and 2. idempotent (should be callable n times with the same parameters returning the same result, as long as the server's state was not changed). This API deletes things through GET.
* Lack of use of HTTP headers, instead of using the Accept header the client has to use an informally defined query parameter
* Lack of descriptive content types (linked to previous point)
* Complete absence of use of HTTP status codes (standard or custom), the API returns a status of 200 in all cases
This is pure and simple (and terrible, since it's over GET) RPC tunneled through HTTP.
RESTful APIs usually represent CRUD operations, each of these letter can be beautifully mapped to request types: - CREATE -> POST - READ -> GET - UPDATE -> PUT - DELETE -> DELETE
Second point: {error: false, value: actual_data} If we have an error variable, what is the HTTP error code then good for? Normal Web Servers use the HTTP error codes for a reason. Besides using standard webframework a json containing only "actual_data" means less code, less errors and so forth...
Third point: URLs should represent the hierarchy: GET /users/43/bookmarks/32442?... is much more beautiful and straight-forward to work with than /api_handler.exe?user_id=43&bookmark_id=32442&operation=get...
Regarding authentication: use a secret API key, that's simple and secure. Everybody does that, from small services to multi million user services like facebook.
As a hint: read the dissertation of Roy Fielding who "invented" REST. In my opinion REST means to exploit HTTP as far as possible instead of using any custom conventions.
http://greenbytes.de/tech/webdav/draft-dusseault-http-patch-...
If they were to change the auth method to use a secret key for signing requests and just call it an RPC API then I don't think there would be a problem.
- Doesn't use HTTP verbs (GET, PUT, POST, DELETE) to retrieve, modify, create and remove objects.
- Doesn't use a restful url path to action on (ie. GET /users/#{user_id} to get a specific user by id, POST /users to create a new user).
- Doesn't use HTTP codes to return results (ie. HTTP 200 for normal operations, 201 for created, 40x for error conditions).
That is specifically one thing which does not apply and is completely irrelevant. Good-looking URLs have nothing to do with REST.
The rest, yes.
He asked it in the context of API restfullness, as is pretty clear from the second phrase.
I was just talking about the restful part of the thing, your urls can look like this:
http://example.org/?wubwub=9cec6c6faef8f7ccefe1bbf409368f1e3d0fa626
and still be part of a completely and perfectly restful service.