This is a basic boilerplate for building rest applications with Elixir/Plug
To install it, you need to clone this repository or download it.
- Make sure you have elixir installed
- Run the command below
git clone --depth=1 https://github.com/imhassane/elixir-plug-rest-boilerplate.git <YOUR_PROJECT_NAME>
The project has already some dependencies required by default.
The mix.exs
file dependencies looks like this:
def deps do
[
{:plug_cowboy, "~> 2.0"},
{:jason, "~> 1.2"}
]
end
All the configurations required can be changed in the config directory depending on the environment.
For the routes and Plug configuration, you can edit the lib/routes/base.ex
file. This file
is responsible for returning responses in the correct format and status.
By default, you can send response either with standard http codes such as 200
or 404
or you
can use atoms defined in the same file such :not_found
which will be converted to 404
or
:ok
which will be converted to 200
.
I've written a story on medium on how to build and test an api with the boilerplate. See the full article here