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

calebjosue
I am not sure if this link have already been shared over this forum, I found it (Edit: on Elixir’s reddit) a couple of hours ago. Web A...
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
ErlangSolutions
We’ve announced our latest webinar with Fred Hebert entitled ‘Testing Erlang and Elixir through PropEr Modelling’. There are a ton of tec...
New
preciz
Last year I had this idea to stop practicing touch typing with gibberish and start using repositories from GitHub as the source of the t...
New
kpanic
Hi everyone, At the company where I work (Taxfix), we prepared an internal Elixir course for our folks. We decided to share it with eve...
New
ambareesha7
there are lot of learning resources and blogs are available but they scattered across, so i’m trying to pooling them in this repo. pleas...
New
zkessin
I have a new free email course on how to best use types in Erlang and Elixir you can sign up here https://elixirtraining.org/types_cours...
New
sonic182
Hi everyone, I’d like to share Livellm, a small open-source Phoenix LiveView chat app built as a reference for integrating llm_composer ...
New
PJUllrich
I’m happy to announce RunElixir.com, a free online guide to Elixir. It aims to answer the questions: How can I get started with Elixir?, ...
New
krishna_vaguelyright
Hi I am new to Elixir, just started learning 3 weeks back. I am building a Chat App with Elixir/Phoenix as backend & React-Native on ...
New

Other popular topics Top

Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
Lily
In templates/appointment/index.html.eex: <%= for appointment <- @appointments do %> <tr> <td><%= appoi...
New
hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a > b) do {:ok, "a"} end if (a < b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 52341 488
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
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
klo
Got a question about when to concat vs. prepending items to list then reversing to achieve appending. So i know lists boil down to [1 | ...
New
Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 126479 1222
New

We're in Beta

About us Mission Statement