zenw0lf

zenw0lf

Tutorial: Building a JSON API with Phoenix 1.3 and Elixir

Hello all!

I just finished a full step-by-step tutorial on how to build a JSON API with Phoenix:
https://lobotuerto.com/blog/building-a-json-api-with-phoenix-and-elixir/

It covers:

  • Create a new API-only Phoenix application —skip HTML and JS stuff.
  • Create a User schema module (model) and hash its password —because storing plain text passwords in the database is just wrong.
  • Create a Users endpoint —so you can get a list of, create or delete users!
  • CORS configuration —so you can use that frontend of yours that runs on another port / domain.
  • Create a Sign in endpoint —using session based authentication.

Any feedback is appreciated!

P.S. Please bear in mind I’m just starting with Elixir and Phoenix. But did my best to try to make it as clear as possible for advanced users from other frameworks (like Rails).

Most Liked

josevalim

josevalim

Creator of Elixir

You can achieve that by simply passing a flag to phx.new:

mix phx.new --umbrella my_app

And then if you need an app that doesn’t talk to the database:

cd my_app/apps
mix new some_api_client

Those capabilities have been there since v1.3. It is not a default but it is definitely promoted as part of Phoenix as a first class concept.

There have been plenty of discussions on why it isn’t the default so maybe someone can post a link to those (in a nutshell, dropping users into an umbrella project without any context may confuse more than help). We also plan to explore and discuss it in the upcoming Phoenix v1.4 book update too.

oldpond

oldpond

There is native support in erlang. Here’s a good tutorial. http://rny.io/elixir/phoenix/ldap/2016/09/20/ldap-authenication-with-phoenix.html

GeetHoobs

GeetHoobs

Thank you, this is just what I need to start, as most tutorials are focusing on full stack.

You’re planning to use JWT, but do you have any recommendation for LDAP bindings for elixir?

Where Next?

Popular in Other Resources Top

ErlangSolutions
Join the team from the Massachusetts Bay Transportation Authority as they explore their work with Elixir from three unique perspectives. ...
New
ErlangSolutions
Hey everyone, We hope you are all safe and well. We have a very exciting new webinar to announce for you. You can register at https://w...
New
GenericJam
It seems like most employers want a reasonably high degree of competence before they’re willing to look at a candidate. Perhaps it’s beca...
New
hectorperez
Hi, I found that a great way to learn is: play with existing livebook notebooks create new notebooks — completely new or just changing ...
New
aifrak
tl;td: My solutions are here and here. Elixir is awesome. Exercism is awesome. Thank you Elixir community. Recently, I have solved all t...
New
arrowsmith
Hi everyone! (Sorry if this isn’t the right place to post this; admins, do what you must.) My name is George Arrowsmith and I’m happy to...
New
realcorvus
This document is to help you prevent a data breach due to your Elixir web application being hacked. It covers strategic and technical wor...
New

Other popular topics Top

JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 42716 114
New

We're in Beta

About us Mission Statement