spirit-example
May 11, 2015 ยท View on GitHub
A simple example of the Spirit web framework
Getting Started
Create an elixir application from scratch
mix new sample_app
cd sample_app
Edit mix.exs file
-
Add
:spiritto OTP application structuredef application do [applications: [:spirit, :logger]] end -
Add
:spiritto depsdefp deps do [ { :spirit, "~> 0.0.1" } ] end -
Run
mix deps.getto install dependencies
Create a controller
Now, create your controller/router inside your lib folder. It should look similar to
defmodule SampleApp do
use Spirit
get "/hello" do
send_resp(conn, 200, "<h1>Hello World!</h1>")
end
match _ do
send_resp(conn, 404, "Not found :/")
end
end
Do not forget to add the application name to your config.exs file
config :spirit, app: SampleApp
Start the application
Now, run mix server and you should have the application running on localhost:4000/hello