Phoenix guide for REST APIs

I’m trying to decide what to use for building REST APIs in Elixir. One often mentioned candidate is Phoenix. It seems like there ought to be a Phoenix guide for doing this. I find a few tutorials on this subject, but nothing that seems comprehensive. Does anyone have any advice?

5 Likes

I would check https://medium.com/@benhansen/lets-build-a-slack-clone-with-elixir-phoenix-and-react-part-1-project-setup-3252ae780a1 where you build a chat app ala Slack, it uses Phoenix to serve the API and React in the frontend, it also makes use of the Channels for real time communication.

1 Like

I did see that but I haven’t got around to going through it. I’m not a fan of large, complex and long running examples for learning a subject matter. I like “as simple as possible, but no simpler” kind of expositions. But thanks for the reminder of that tutorial. Actually, I very much want to learn React better as well so I would be killing two birds with one stone.

I didn’t find much examples on maru, but there are official ones

I gotta say I was looking to do something simple enough, and using Plug, Cowboy, HTTPoison, and Poison libs did the trick.

I wasted a lot of time looking at the perfect framework for me and my answer was I didn’t need one.

Right now is a difficult time to find good resources on Phoenix, everything being on 1.2 all the libs are getting ready for the new contexts and stuff, I would avoid it if I don’t need the rest for now, and Im trying to build something simple.

Something like maru will help with a basic REST API

The reason there is not much docs on it is because it is just that simple in Phoenix. Also, Phoenix calls them ‘resource’ routes, so if you look at that part in the manual you will see how to use it. :slight_smile:

In general a REST/resource path is just like any other normal controller, just with a helper function so you do not have to define all the individual parts yourself, you only have to implement the index/edit/new/show/create/update/delete calls in your controller is all. :slight_smile:

Just a note - I was starting a new Rest API myself and got diverted into GraphQL and Absinthe as an alternate standard for developing a robust api. It may be an alternative that works for you.

1 Like

The GraphQL protocol is pretty awesome, and Absinthe is fantastic for using it in Elixir!

2 Likes

The simpler the better. However, it’s only simple if you know how to do it. The front page of the Phoenix website says “Build APIs…”. The guides very much emphasize Phoenix for server rendered apps. A simple guide with specific instructions for building just REST APIs would be very helpful for API-only users.

4 Likes

I’m building an API in Phoenix with the --no-html --no-brunch flags.
As for the resource part I’m using ja_serializer

If I can find the time I’ll write up a small blog post about it

1 Like

If you don’t need Ecto either you can do --no-html --no-brunch --no-ecto