Skip to Main Content
Mastering Elixir
book

Mastering Elixir

by André Albuquerque, Daniel Caixinha
July 2018
Intermediate to advanced content levelIntermediate to advanced
574 pages
14h 7m
English
Packt Publishing
Content preview from Mastering Elixir

Implementing a JSON API

Up to this point, we've been focusing on serving browser requests and returning HTML responses. In this section, we'll see how to extend the ElixirDrip application with a JSON API, giving our users the ability to interact with their files outside the browser. To demonstrate how to accomplish this, we'll implement the index action of the file controller, along with the ability to log in via the API. As usual, let's begin by looking at our updated router:

$ cat apps/elixir_drip_web/lib/elixir_drip_web/router.ex defmodule ElixirDripWeb.Router do  use ElixirDripWeb, :router  # ...  pipeline :api do    plug(:accepts, ["json"])  end  scope "/", ElixirDripWeb do    pipe_through(:browser) resources("/files", FileController, only: ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Testing Elixir

Testing Elixir

Andrea Leopardi, Jeffrey Matthias

Publisher Resources

ISBN: 9781788472678Supplemental Content