/first-api-elixir

Simple API for a Meetup at Elixir Asturias https://www.meetup.com/Elixir-Asturias/events/257928606

Primary LanguageElixir

First API with Elixir

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.

Design API

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}

Environment Setup

We'll need to install:

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.

Running it!

  • 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.