Erlang Web Libraries & Frameworks

来源:互联网 发布:机顶盒点播软件下载 编辑:程序博客网 时间:2024/05/18 05:44

转载:http://lenary.co.uk/erlang/2011/08/erlang-web-libraries/


I'll try to keep this updated as more information comes to light. Please email me if anything is factually incorrect.

Recently I needed to compare a few Erlang web libraries and frameworks for a friend who was writing a simple internal API endpoint. He suggested I should publish the rundown for others, so here it is.

Thanks to everyone that has provided corrections and updates since I originally published this post.

Yaws

Thanks to Steve Vinoski for pointing out I'd missed Yaws

Yaws is a high performance web server aimed mostly at serving dynamic web pages. However, usingappmods, it is possible to construct an API instead.

The Yaws documentation is good, and it looks very well put together. It can be embedded into a supervision hierachy.

Mochiweb

This one seems to be one of the most-used libraries for API development with Erlang. Overall it does the job, but it does have a few quirks.

The docs for mochiweb aren't very good, and it uses parameterised modules quite a lot, which I don't like. That said, it's trivial to embed into another erlang application.

Misultin

Thanks to pointers from Andrew Thompson, I added this section, as well as the sections on Cowboy and Zotonic

Misultin seems very similar in general architecture to Mochiweb, except that it also includes support for websockets.

The examples are well put-together and clear. There is also copious documentation intheir wiki.

Cowboy

Cowboy is also fairly similar to Mochiweb, only without the parameterised modules and instead using whole modules to handle requests. Cowboy is (I think) one of the only fully-binary HTTP Servers, for increased speed and lower memory usage.

There are examples of how to use it in this Repository on github.

httpd

The httpd module comes bundled as part of the inets application, which suggests that it's good enough for lots of uses, and if you need to get up and running quickly. httpd is the only one on the list with support for WSGI- or Rack-like middleware, for chaining arbitary request handlers together.

Unfortunately, it also has a fixation on using one single callback function and the docs aren't that great. To help when writing httpd mods, Garrett Smith wrotemodlib which is a wrapper library to help clear up the API somewhat.

SimpleBridge

Thanks to Loïc Hoguin and Jesse Gumm for both poining out SimpleBridge.

Speaking of wrappers, SimpleBridge is a project "to provide a simple, standardized interface to Erlang HTTP Servers". What this means in practice is that you wrap the framework you're using's request and response objects in some SimpleBridge Adapters so that it's slightly easier to change which library you're actually using.

I feel that SimpleBridge doesn't quite go far enough to be a HTTP Library adapter. It has support for Mochiweb, Inets httpd and Yaws, with support for Misultin in the pipeline.

webmachine

This is built upon mochiweb, but abstracts you away from lots of the lower-level HTTP semantics. Instead it bills itself as a “REST Toolkit”.

For Basic RPC over HTTP applications, this isn't what you'd use, however, it makes lots of sense if the application is very resource-orientated. As it's come out of Basho, I'd expect it to be well written and documented.

Nitrogen

Thanks to Jesse Gumm for telling me that it is indeed possible to write an API endpoint with Nitrogen.

Nitrogen is aimed more at building functional user interfaces. It brings its own system for sending events back and forth between the client and the server which I find very interesting. Here's anIntroduction to Nitrogen.

As every page is just a module, and templates are optional, it is trivial to construct an API with Nitrogen.

Zotonic

Zotonic is a fully-fledged CMS, with included support for WebSocets and Comet. It is easy to extend, and there is quite a lot of documentation on their site.

From what I can tell, it uses webmachine and nitrogen underneath, but it is also possible to define your own API inside a site, complete with OAuth support.

Chicago Boss

This framework is much closer to what Rails is for Ruby. It has models and lots of already-implemented behaviour to bring you up to speed quickly. Probably too complex for a simple API, but it depends on what you're doing.