Elixir and Cowboy

As you can know from previous blog post i started to learn/use Elixir language for my hobby project. Elixir is programming language which built on top of Erlang virtual machine and we can use libraries which was written in Erlang. In this post i will try to tell how to use  Elixir with Cowboy web server. You can find some different examples in the Internet about usage Elixir with cowboy:
I will tell how to use Elixir with :cowboy_static handler. First of all we must create Elixir project with mix:
mix new testElixirWithCowboy
mix util will generate Elixir project skeleton. Now let's make frontend part. Create priv directory in the our project root directory. And there index.html, js and css directories. I put my favorite Angular.js and bootstrap.css to the js and css directory, but you of course can use any js/css libraries which you will want. Now add simple html template:

And set up routing in cowboy and start it. Open lib/testElixirWithCowboy.ex and add there:

Run application with executing:
iex -S mix
And now you can see you web page at http://localhost:8080/

Happy codding, @0xAX

No comments: