dwyl / learn-phoenix-framework

:fire: Phoenix is the web framework without compromise on speed, reliability or maintainability! Don't settle for less. :rocket:
646 stars 45 forks source link

How to create a Phoenix app for API only #132

Open SimonLab opened 4 years ago

SimonLab commented 4 years ago

I'm looking at creating the most basic Phoenix application which can be used for creating an API. I know that Webpack is not required as an API will only returns json so managing assets is not necessary. The html view and templates are also not required.

You can find the documentation on how to create a new project with mix help phx.new: image

So we need to pass the --no-webpack and --no-html options when creating a new project. ref:

nelsonic commented 4 years ago

@SimonLab thanks for opening this issue! 🙌 Please capture as much detail as you can as we've been meaning to write a beginner-friendly Elixir API example app ever since https://github.com/dwyl/learn-elixir/issues/102 ... ⏳

SimonLab commented 4 years ago

I'm starting with Phoenix as it offers a lot of convenient features and because I've spend most of the time working with Phoenix itself than bare Elixir but I will try to research and implement an API server with only Elixir.

nelsonic commented 4 years ago

@SimonLab I don't have much interest in building Elixir (Web) Apps without Phoenix. Having a "framework" to organise code offers more benefits than the "performance overhead". Don't waste time on building an API without Phoenix. 👍

SimonLab commented 4 years ago

I've now been rewriting (multiple times) the documentation on how to create an API with Phoenix. I've kept the steps simple and I'll add more features on the next PRs:

nelsonic commented 4 years ago

@SimonLab it's only worth adding Postgres for storing data that needs to be in Postgres. the quotes.json file can easily be served without Postgres. 💭 If your plan is to create a Quotes App that allows people to add quotes fair enough. 🤔 But there's a chance that you're creating complexity for the user without too much benefit.

SimonLab commented 4 years ago

My idea with Postgres is to be able to add and edit some quotes to show specifically how to create post and put endpoints/controller and how to send the request with a client, for exemple with curl. I agree it might add some complexity but I think it can still be easy to follow has the code added won't be huge and the documentation will explain where to find the configuration for Postgres.

nelsonic commented 4 years ago

@SimonLab sounds good.