Live data from Hacker News

Stop Writing REST API Clients

ttezel.github.com

111–120 of 137 posts

Re: Stop Writing REST API Clients

#111

I want to give you an idea of how bad things are with REST Api Client . This is a Maven POM for Google APIs for java web project that uses Google APIs for Profile, Drive and Oauth2. Its insane: 4.0.0 com.google google 5 com.google.api.client google-plus-java-webapp-starter war 1.0.0 google-plus-java-webapp-starter Web application example for the Google+ platform using JSON and OAuth 2 https://code.google.com/p/google…

Argh, if this is what REST looks like, we should just go back to SOAP.

Re: Stop Writing REST API Clients

#114
post #64

Earlier quoted context omitted.

Yes my argument is simply that we publish API specs in a machine-readable format to avoid wasting time implementing clients repeatedly. WSDL and WADL had good intentions at heart, but XML is ugly. JSON is nice since it's human-readable and light. Why not publish JSON versions openly for REST APIs, reducing implementation cost for clients?

XML is more human readable than JSON, to my eyes.

That may be so, but most opinions I hear in discussions about XML vs JSON say that JSON is more readable, probably because it's less redundant and similar to data structures found in some programming languages.

Re: Stop Writing REST API Clients

#115
post #73
post #64

Earlier quoted context omitted.

Yes my argument is simply that we publish API specs in a machine-readable format to avoid wasting time implementing clients repeatedly. WSDL and WADL had good intentions at heart, but XML is ugly. JSON is nice since it's human-readable and light. Why not publish JSON versions openly for REST APIs, reducing implementation cost for clients?

> ... my argument is simply that we publish API specs in a machine-readable format ... > ... XML is ugly. JSON is nice since it's human-readable and light. ???

Yes, there are some dots you need to connect between his two statements. I'm assuming that he meant the following: those machine-readable specs also need to be read by humans at some point, just like code, and, since JSON is more readable, he proposes using it instead of XML.

Re: Stop Writing REST API Clients

#116
post #94
post #74

Earlier quoted context omitted.

You could use OPTIONS /somePath?

Thank you for being realistic. REST means more than just GET, POST, PUT, DELETE. Some may make the excuse that call OPTIONS /path isn't straightforward, but I have no clue how you could get more obvious than that.

The problem with OPTIONS is it doesn't describe anything about the data the resource returns.

I really wish there was a DESCRIBE verb that would return a structure of what is expected to be received/sent.

Then microformats could spring up around datatypes returned by DESCRIBE. This is of course very XML.

Edit: This would also allow for automatic discovery of new APIs.

Re: Stop Writing REST API Clients

#117
post #74

Earlier quoted context omitted.

I agree. The promise of REST APIs is that will be self describing, but for that benefit to be realized, we need general purpose REST clients that can "discover" everything they need to know given just a root uri. Are there any such clients? And no, web browsers do not count.

You could use OPTIONS /somePath?

I built out a proof of concept on top of my open source project:

https://github.com/caseysoftware/web2project-slim

But one of the things I did a little differently is that instead of writing the code and then the docs separately, I pass the validation information from the object itself.. so the API layer doesn't have to know any of it in advance. It can pass that along to the end clients.

I'm not convinced this is the solution but it mostly works for now and would love any & all feedback.

My next proof of concept will be to use Javascript to retrieve the required fields and decorate a simple html form.

Re: Stop Writing REST API Clients

#118
post #15

All that these sorts of description produce is a low-level API. That can be useful, but what's really needed are high-level APIs that provide meaningful semnatics: my $me = Facebook->new( username => 'autarch' ); $me->post_status("I'm on Hacker News writing this comment"); my $friend = Facebook->new( username => 'imaginary' ); $me->post_on_wall( $friend, "Hey buddy, I am on Hacker News writing this comment" );

Exactly. And this is what clients can provide over generic, one-size-fits-all solutions: fluent, idiomatic, and terse access to APIs.

Here's another way to phrase it. A good API is based on the data and actions related to a specific domain of knowledge. Generic solutions produce APIs that are oriented around the communications protocol (REST).

On the client side, I don't really care (too much) if something is a POST or PUT, I want to send a message or update a repository's metadata or share a photo.

Re: Stop Writing REST API Clients

#119
post #42

Am I the only one who doesn't like receiving direct orders from article titles?

Writing using authoritative language is very common, and widely considered a best practice. I highly recommend you simply accept it as what it is: the way some people communicate, especially online. It's not worth your time/attention/care to think about this.

Writing 'authoritatively' is used as a pop-culture substitute for reasoned argument. I find that it's a good litmus test for determining who I should ignore.

Re: Stop Writing REST API Clients

#120
Given that the prevailing sentiment is that REST is self-describing and the API description doc is unnecessary, are there any examples of client generators that work directly off of a REST service?

I'm curious how this works in practice. What about authorization and parts of the API that are only available to certain users, does the client generator need to be authenticated? Are there standards for describing the meta-data associated with URLs (validation, optional parameters, etc.)?

Post reply on HN