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

Blond11516
Does anyone have resources (articles, talks, etc.) they can share about “modern fullstack apps”? By “modern fullstack” I mean dynamic, s...
New
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
ErlangSolutions
This month we’re excited to host Tyr Chen, VP of Engineering at ArcBlock, on our webinar. ArcBlock are founding sponsors of the Erlang E...
New
drobban
Hey everyone, Some of you might remember 4Clojure from back in the day—it was a fantastic site with a series of coding challenges for th...
New
ryan-senn
I’m learning Elixir and started to go through the Project Euler problems. While the problems are great, the UX is very limited. I’ve buil...
New
ErlangSolutions
Webinar announcement :loudspeaker: We’re kicking 2020 off with a live coding demonstration of how you can build Tetris in Elixir. It’s a ...
New
blackode
Elixir Quiz that tests your Knowledge in Elixir Programming. Elixir Functional Programming Test Intermediate level :pen: 30 questions ·...
New
wolfiton
Cool way to learn service workers by playing this game Also this game may not work well in the latest Firefox but works in Opera
New
landonwilkins
Hi! My apartment’s walls are blank. I want to fill at least one with Elixir diagrams. Links to Diagrams GitHub - benjamintanweihao/eli...
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

Other popular topics Top

johnnyicon
Hi all, I’ve just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I’m trying to use Postgres...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
Lily
In templates/appointment/index.html.eex: <%= for appointment <- @appointments do %> <tr> <td><%= appoi...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
AstonJ
Please see the new poll here: Which code editor or IDE do you use? (Poll) (2022 Edition) It’s been a while since we first asked this, I...
208 31142 143
New
boundedvariable
I am going through the kafka architecture. All the features what the kafka is providing are already in Erlang. I would like hear your opi...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

We're in Beta

About us Mission Statement