开发者

Choice of framework for an API server

I'm looking to build an API server with the following traits:

  • Serves JSON/XM开发者_运维技巧L HTTP requests only (no web-pages).
  • Is mostly DB intensive, not so much CPU intensive.
  • Should be highly scalable.
  • Has versatile front-ends: web-browsers, native mobile (Android and iOS for now)

I am experienced with Apache Tomcat, httpd, MySQL and PHP, so these are obviously my default choices. However, before automatically going there:

Would you recommend any other constellation of technologies (Node.js, Rails...) for this type of server?

I'm mostly interested in performance/scalability related advantages/disadvantages.


DB intensive means it's IO intensive. Node.js provides asynchronous IO and as a bonus JavaScript speaks json natively.

Checkout: http://www.nodecloud.org/ for resources.

And here's a simple example to get you started:

var express = require('express');
var Client = require('mysql').Client,
  sqlclient = new Client(),
  sql_database = '...';
sqlclient.host = '...';
sqlclient.user = '...';
sqlclient.password = '..';
sqlclient.connect( function (err) {
  if( err ) {
    throw(err);   
  }
  console.log('connected to mysql on ...');
});
var query = 'SELECT . . . ';

var app = express.createServer();

app.get('/', function (req, res, next) {
  sqlclient.query('USE '+sql_database);
  sqlclient.query( query, function (err, results, fields) {
    res.send(JSON.stringify(results));
  });
});

app.listen( 3000 );


I would personally use node.js.

Serves JSON/XML HTTP requests only (no web-pages).

Nowadays most API's just only support JSON and I would advice you to do the same. In node.js creating JSON is just as simple as calling JSON.stringify on an object.

Is mostly DB intensive, not so much CPU intensive.

node.js does non-blocking IO and has very good performance with some databases like for example redis, mongodb.

Should be highly scalable.

node.js is very fast and you can use NGinx to scale if single box does not cut it, but probably one single box will be enough.

Has versatile front-ends: web-browsers, native mobile (Android and iOS for now)

I think your API should probably provide oauth like most others API's do. This is the only problem with node.js I think because only one library is available and I don't know the quality of this package


Rails does REST out of the box. It has good support for JSON responses, and unsurpassed ORM for dealing with and abstracting the database interaction stuff and organizing your code according to resources.

Shortcut: lookup the as_json method.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜