Building an API

I want to transfer an API that was built using fastapi in python to elixir. Should I use phoenix or plug? Phoenix is excellent for web development, but is it overkill for an API that serves another frontend built in js? plug on the other hand seems suitable from what I’ve read but I also read that it needs more boilerplate. The API is fairly complex and plug seems suitable to me. I just wanted to know if there is anything that I should be warned about regarding plug and if there are some tweaks to phoenix to make it similar to fastapi (ie: remove the fullstack web development packages).

Thank you.

Take a look at the API-only applications section of Phoenix docs.

2 Likes

Thank you

1 Like

Phoenix, while making your app have a little more files, is much more future-proof than any almost barebones Plug app you might do.

Go for Phoenix. It might be slightly annoying to begin with but will very quickly pay dividends.

1 Like

I’d go with Phoenix too. We build our APIs with it and it has been great so far.

The Phoenix tutorial will have you install the phx.new command. Once done, call mix help phx.new in your terminal and you will see options to disable HTML, LiveView, Tailwind and ESBuild when creating a new Phoenix project.

1 Like

I would say go with Phoenix unless it is a very simple API that won’t grow in the future (which does not seem to be the case). The overhead of phoenix is negligible but makes many things easier.

Just exclude everything you don’t need:

mix phx.new my_api --no-assets --no-gettext --no-html --no-mailer

2 Likes