Canillita (Your First Erlang Server) — V2
Harenson Henao wrote this on January 04, 2016
Let’s start this new year with a big bang!
Do you remember when you learned how to create your first web server with Erlang? Well that’s so 2013! The libraries we used back then had been updated, new libraries had been created; even Erlang itself had been improved… a lot. So, let’s do it again! In this post I will show you how to create a very basic, but yet useful RESTful server using some widely known Erlang libraries. It will not be enough to teach you how to program in Erlang and I won’t dive into the core aspects of the language itself. For that you can always learn you some erlang for great good! ;). On the other hand, if you’re an experienced Erlang programmer and you need a RESTful server with SSE capabilities for your application, you may use this example as a starting point to build your system.
What’s in this article
These are the components, protocols and features that I’ll use and show in this article. Each one comes with a link where you can find more information about them.
- SSE: a technology from where a browser gets automatic updates from a server via HTTP connection
- cowboy: the ultimate server for the modern Web, written in Erlang with support for Websocket, SPDY and more
- cowboy-trails: Some improvements over Cowboy Routes
- cowboy-swagger: Swagger integration for Cowboy (built on trails)
- sumo_db: a very simple persistance layer capable of interacting with different db’s, while offering a consistent api to your code
- sumo_rest: Generic Cowboy handlers to work with Sumo
- lasse: Server-Sent Event (SSE) handler for Cowboy
- mixer: Mix in functions from other modules
In 2013 CanillitaV1 was still using SSE, Cowboy and sumo_db. In this new version we will be introducing some new libraries: cowboy-trails, cowboy-swagger, sumo_rest, lasse and mixer. All will be explained later in this blog post.
What’s not in this article
You will not find the following stuff here:
- HTTP authentication, QueryString and many other things — you can easily add these to your RESTful server using Cowboy
- Complex persistency operations — with sumo_db you can do much more than what I did here
- Complex swagger structures — for those you have to check both swagger and cowboy-swagger docs.
- Tests — Although the project in github was built with TDD, I will not go into detail on how that works (We have multiple posts about it on our blog already)
…continue reading at inaka’s blog
Originally published at inaka.net on January 4, 2016.