In this repository it will be the code to create an API Elixir. We're going to implement a simple RESTful API with Elixir and Ecto for database management. View the slides here.
Our API serves albums and artists as resources, defining a very simple Music Store.
The endpoints will be:
-
GET /api/artists
-
GET /api/artists/{id}
-
POST /api/artists
-
DELETE /api/artists/{id}
-
GET /api/albums
-
GET /api/albums/{id}
-
POST /api/albums
-
DELETE /api/albums/{id}
We'll need to install:
-
Elixir
- Mac:
brew install elixir
- Windows: download the installer
- Linux: check your distribution and download the installer
- Mac:
-
PostgreSQL
- Mac: download Postgres.app
- Windows & Linux: download
And following dependencies:
- Ecto: see documentation here.
- Postgrex: adapter for Postgres. See documentation here.
- Plug: specification for composable modules between web applications and connection adapters. See documentation here.
- Cowboy: HTTP Server. See documentation here.
- Jason: JSON implementation. See documentation here.
- Install dependencies with
mix deps.get
- Create and migrate your database (check credentials on config.exs) with
mix ecto.create && mix ecto.migrate
- Start endpoint with
mix run --no-halt
You can try each service with Postman or curl in localhost:4000.