News for hackers. Stuff that matters.

Ask HN: The best language for writing RESTful APIs?

I've used flask, rails, and padrino (sinatra).

Flask was my favorite but is hard to keep organized without much of a toolkit or recommended dev patterns baked in. I recognize that blueprints really help, but a consistent cross-project organization would be nice.

The transition to padrino was welcomed due to a lot of basic structure that is consistent in all projects, but unsustainable due to a functionally dead community (#sinatra has 25 people at max and nobody talking, #padrino has maybe 8).

Rails is far too much bloat to just be serving JSON (benchmarks show that sinatra is 4-8x faster...) and implies TOO strict a structure to development (also, being a python person...I don't appreciate magic).

What do you recommend?

( 21 comments | 10 points | on HN )
Re:Ask HN: The best language for writing RESTful APIs? by jakerella86 on Tuesday June 16, 2015 @02:34PM (#9727858)
I'd agree that Node.js is pretty dang nice for RESTful APIs. The fully asynchronous nature means really great throughput on the server, especially when most of your processing time is spent in DB or file I/O (as is often the case in APIs). As for disadvantages... I dunno. I guess if you don't really know JS very well it could be difficult to get into, and good developers are harder to find than in some other languages. But as a platform for APIs it's pretty solid.

As for a guide... There's a guide for LoopBack specifically here: http://docs.strongloop.com/display/LB/Getting+started+with+L... That framework was written specifically for writing REST APIs.

Re:Ask HN: The best language for writing RESTful APIs? by dpweb on Tuesday June 16, 2015 @10:17PM (#9729780)
Here's a minimal framework for NodeJS. https://github.com/digplan/rex I have read some good things about other langs, but I'll usually use Node.
Re:Ask HN: The best language for writing RESTful APIs? by bjourne on Tuesday June 16, 2015 @05:10PM (#9728722)
> Rails is far too much bloat to just be serving JSON (benchmarks show that sinatra is 4-8x faster...)

Does it matter 1 bit? If you can't demonstrate that it does, you might as well choose the framework with the best mascot and Django's mascot is pretty damn awesome.

Re:Ask HN: The best language for writing RESTful APIs? by hackerboos on Tuesday June 16, 2015 @09:52PM (#9729711)
Sinatra is faster but enjoy writing the boilerplate.

I'll have my Rails API up in half the time. Why worry about scaling before you have to?

Re:Ask HN: The best language for writing RESTful APIs? by ianseyer on Friday June 19, 2015 @02:42PM (#9746790)
That sounds awfully like famous last words...

In addition, I would say the mentality of scalability when constructing applications is part and parcel of the design ideology of ruby, but too often far removed from its practice.

I see no reason to prefer Rails API. It is a reverse-frankenstein situation whereby they had the monster, and started removing limbs...

Re:Ask HN: The best language for writing RESTful APIs? by ianseyer on Tuesday June 16, 2015 @05:20PM (#9728766)
What? I legitimately did not understand what you just said.

Django, similarly to rails, has far too much bloat and is tediously layed out. An entire rant aside, Django is becoming increasingly unpythonic and more rubylike, imo.

Re:Ask HN: The best language for writing RESTful APIs? by brickcap on Tuesday June 16, 2015 @03:56PM (#9728339)
I would recommend openresty. A library that allows you to script nginx using a lightweight,easy to learn language lua. You get all the advantages of nginx (unmatched speed and resource efficiency) along with the ability to "inject" lua code into it's event loop. Which should be a compelling enough reason for you to give it at least some serious thought.

As far as organization of code is concerned openresty does not impose any restrictions on you. But since it is just lua you can bundle you code into modules. And then you can use those modules using "require" much like in node js (though it is slightly different)

Also there is lapis[1] and sailor[2] if you are looking for something more organized.

[1]https://github.com/leafo/lapis [2]https://github.com/Etiene/sailor

Re:Ask HN: The best language for writing RESTful APIs? by volgodark on Sunday June 21, 2015 @07:02AM (#9752936)
What about PHP ? You may try Aisel, its uses clean object-oriented PHP https://github.com/ivanproskuryakov/Aisel.

Aisel based on principles of REST architecture combines two different and independent frameworks - Symfony2 with a robust PHP community and progressive AngularJS.

Re:Ask HN: The best language for writing RESTful APIs? by treve on Tuesday June 16, 2015 @04:30PM (#9728508)
PHP is also a dependable, boring, but proven choice.
Re:Ask HN: The best language for writing RESTful APIs? by centrinoblue on Tuesday June 16, 2015 @02:12PM (#9727705)
node.js / LoopBack - super fast prototyping, flexible, open js/json
Re:Ask HN: The best language for writing RESTful APIs? by ianseyer on Tuesday June 16, 2015 @02:19PM (#9727756)
Also, care to explain some of the DISadvantages of using node for APIs?
Re:Ask HN: The best language for writing RESTful APIs? by angersock on Tuesday June 16, 2015 @02:33PM (#9727850)
So, the biggest thing that can't be worked around is that the number type in Javascript doesn't support arbitrary-length integers. That means that you can't blindly trust numeric IDs for resources (though it'll take you a while to hit them)--instead, you'll have to do things like specify string versions of those id's. Twitter ran into this, I believe, and it's something to be aware of.

The other disadvantage of using Node is that the ecosystem is still not completely agreed on what to use--for my 0.02USD, I'd look into HAPI + Swagger.

Also, if you don't know about promises or generators, you're going to write really really ugly Node code. That said, it's pretty easy to pick up.

Re:Ask HN: The best language for writing RESTful APIs? by altsang on Tuesday June 16, 2015 @02:30PM (#9727831)
understanding asynchronous coding in JavaScript - e.g. callback hell, flow control, it's the tradeoff to efficient and scalable processing
Re:Ask HN: The best language for writing RESTful APIs? by ianseyer on Tuesday June 16, 2015 @02:19PM (#9727752)
having never used node, could you point me to a good tutorial/guide on using the two in tandem?
Re:Ask HN: The best language for writing RESTful APIs? by sickeythecat on Tuesday June 16, 2015 @02:32PM (#9727843)
Might want to poke around here for tutorials geared at devs coming from other languages: https://strongloop.com/node-js/node-js-get-started-java-php-...
Re:Ask HN: The best language for writing RESTful APIs? by centrinoblue on Tuesday June 16, 2015 @02:40PM (#9727905)
Re:Ask HN: The best language for writing RESTful APIs? by altsang on Tuesday June 16, 2015 @02:26PM (#9727799)
for this specific use case? Node.js using LoopBack.io. I/O platform with a framework that was specifically designed for this use case, built on top of Express to save you time.
Re:Ask HN: The best language for writing RESTful APIs? by pcx on Thursday June 18, 2015 @07:10AM (#9737820)
You haven't used Django Rest Framework yet! I am 90% confident you will love it ;).
Re:Ask HN: The best language for writing RESTful APIs? by thamizharasu on Wednesday June 17, 2015 @09:38AM (#9731643)
Java with JAX-RS api (Jersey framework) is my choice. Very clean API
Re:Ask HN: The best language for writing RESTful APIs? by romanovcode on Friday June 19, 2015 @09:02AM (#9744361)
Easy answer. C# WebApi
Re:Ask HN: The best language for writing RESTful APIs? by bradhe on Tuesday June 16, 2015 @07:44PM (#9729347)
golang is my goto.