Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/emancu/spirit
A microframework for web development on Elixir
https://github.com/emancu/spirit
Last synced: 3 months ago
JSON representation
A microframework for web development on Elixir
- Host: GitHub
- URL: https://github.com/emancu/spirit
- Owner: emancu
- Created: 2014-07-15T06:00:32.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2015-08-07T05:15:26.000Z (over 9 years ago)
- Last Synced: 2024-10-25T01:43:32.927Z (3 months ago)
- Language: Elixir
- Size: 144 KB
- Stars: 41
- Watchers: 6
- Forks: 8
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Spirit
======n. a microframework for web development.
## Description
We are big fans of [cuba] for `ruby` so we wanted to contribute to `elixir`
community with a similar microframework.The intention of this project is to learn how `elixir` works and create a
framework for our upcoming projects.We know there are many frameworks like [phoenix], [clint], [sugar] and others
which we will be watching to learn and contribute but we still want to build
a new one. It will teach us a lot!## Installation
Add `:spirit` to deps
```elixir
defp deps do
[
{ :spirit, "~> 0.0.1" }
]
end
```And run `mix do deps.get, deps.compile`
## Usage
Here's a simple application:
```elixir
# cat lib/sample_app.exdefmodule SampleApp do
use Spiritget "/hello" do
send_resp(conn, 200, "Hello World!
")
endmatch _ do
send_resp(conn, 404, "Not found :/")
end
end
```And the config file
```elixir
# cat config/config.exsuse Mix.Config
config :spirit, app: SampleApp
```To run it, just do `mix server` and start browsing your application.
> Check [spirit-example] to see the full example and step-by-step guide.
## Composition
You can compose as many Spirit applications as you want using `forward`.
This is a recommended practice when you have nested routes or want to group
routes based on a criterion.```elixir
defmodule Users do
use Spiritget "/" do
send_resp(conn, 200, "Users index")
endget "/:id" do
# Show the User with `id`
endpost "/" do
# Create a new user
endmatch _ do
send_resp(conn, 404, "Not found")
end
enddefmodule MainApp do
use Spiritget "/hi/:name" do
send_resp(conn, 200, "hello #{name}!
")
endforward "/users", to: Users
get "/hello/*_rest" do
send_resp(conn, 200, "matches all routes starting with /hello")
endmatch _ do
send_resp(conn, 404, "Not found")
end
end
```[cuba]: https://github.com/soveran/cuba
[clint]: https://github.com/lpil/clint
[sugar]: http://sugar-framework.github.io
[phoenix]: http://phoenixframework.org
[spirit-example]: https://github.com/citrusbyte/spirit-example