DEV Community

Cover image for Elixir: Building a Small JSON Endpoint With Plug, Cowboy and Poison

Elixir: Building a Small JSON Endpoint With Plug, Cowboy and Poison

Jon Lunsford on May 10, 2019

There’s been many times when I’ve just wanted to add a simple JSON endpoint to an app to, expose a service, or process webhook events, without the ...
Collapse
 
tiagonbotelho profile image
Tiago Botelho

Great walkthrough of using Plug, Cowboy and Poison altogether! I've actually recently wrote a deep-dive on Plug.Cowboy to understand a bit more how Cowboy handled incoming HTTP requests, which I found super interesting: charta.dev/tours/plug_cowboy

Collapse
 
combinedcognitions profile image
CombinedCognitions

thank you for throwing in the link here ... was really looking for something of sorts

Collapse
 
jonlunsford profile image
Jon Lunsford

Awesome stuff!

Collapse
 
pavonz profile image
Andrea Pavoni

Very interesting stuff! I use Phoenix and I did know that its router is a set of macros for the Endpoint. This minimal implementation is very cool and useful to know :-)

On a side note: have you tried Jason instead of Poison? I've started using it, pretty the same API of Poison, also, if I recall correctly, it's the default encoder for Ecto 3.x.

Curious to see the deployment part.

Collapse
 
shmink profile image
Tom Nicklin

Thank you so much for this. It's exactly what I needed.

Collapse
 
pierreaurele profile image
Pierre Aurèle Martin

Thanks :) Just ran my first Elixir endpoint

To try it, just use iex -S mix and go to your favorite browser :)

mix run doesn't work but I'll figure it out !

Collapse
 
shmink profile image
Tom Nicklin

mix run --no-halt is what you need. Would recommend postman though rather than a browser otherwise, you get a load of warnings in the logger about favicons.

Collapse
 
michalvalasek profile image
Michal Valasek

Thanks for the article, looking forward to the followup on deployment!

Collapse
 
jonlunsford profile image
Jon Lunsford

Thanks for reading! Yeah, I will be walking through a few methods of deployment:

  1. Setting up dokku on digital ocean (for hobby or proof of concept deploys)
  2. Production deploys with ansible on AWS
Collapse
 
sloppystone profile image
𝕾𝖑𝖔𝖕𝖕𝖞𝕾𝖙𝖔𝖓𝖊

Thank you for this! Would really like to see a quick tutorial on deploying as well!

Collapse
 
kristerv profile image
Krister Viirsaar

hey, nice and useful. would be curious about how you deploy also!

Collapse
 
lgbanuelos profile image
Luciano García Bañuelos

Very interesting article! I was wondering if you know how to add support for CORS. That would add the cherry the cake!

Collapse
 
logicmason profile image
Mark

Fun!

Collapse
 
jonlunsford profile image
Jon Lunsford

🙌