Using Phoenix to create a REST API
2 min read
- Install Elixir and Erlang
- Install Hex
- Install Phoenix
- Create a new Phoenix project (since we are creating a REST API, we will skip some of the options)
Options:
folder name
- The name of the folder where the project will be created.app name
- The name of the OTP application.database
- Specify the database adapter for Ecto. One of:postgres
- via https://github.com/elixir-ecto/postgrexmysql
- via https://github.com/elixir-ecto/myxqlmssql
- via https://github.com/livehelpnow/tdssqlite3
- via https://github.com/elixir-sqlite/ecto_sqlite3
Defaults topostgres
.
--no-install
- Skip installing dependencies.--no-live
- Skip LiveView.--no-assets
- Skip assets.--no-html
- Skip HTML views.--no-dashboard
- Skip the Phoenix Dashboard.--no-mailer
- Skip generating Swoosh mailer files.--binary-id
- Use binary UUIDs for primary keys.
Example:
- Change directory to the project folder
- Change the database configuration in
config/dev.exs
- Install dependencies
- Create the database
- Start the Phoenix server
- Visit
http://localhost:4000
in your browser to see the Phoenix welcome page.
Resources: