官术网_书友最值得收藏!

Running the Phoenix server for the first time

There are two ways to start up the Phoenix server, and now that the application is set up and the database is there to support our application, we can move on to actually running it! The two different ways to run your application are either via Mix phx.server or in the IEx console. In the context of your application requiring debugging support via IEx, you need -S Mix phx.server. As a general rule, I only run my application in a local development environment through IEx. This allows you to get interactive debugging via IEx.pry, as well as the ability to perform things like Ecto queries or test calling public functions in modules.

Remember when we talked about the interactive help functions that are built-in to Elixir and can be accessed via IEx? Well, you can do the same thing with Phoenix functions, too! For example, let's say we want to know a little more information about how we send out JSON content directly from a controller, as shown in the following example:

iex(4)> h Phoenix.Controller.json

def json(conn, data)

Sends JSON response.

It uses the configured :format_encoders under the :phoenix application for
:json to pick up the encoder module.

## Examples

iex> json conn, %{id: 123}

Okay, so we now have our application and we have things up and running. If we visit our browser window, we should see the Phoenix startup page, as follows:

主站蜘蛛池模板: 红安县| 武川县| 株洲县| 社旗县| 威宁| 吴桥县| 拉萨市| 景泰县| 南丹县| 沛县| 洛隆县| 涡阳县| 喀什市| 惠东县| 潞城市| 兴安县| 苏尼特右旗| 安达市| 安乡县| 常宁市| 翁牛特旗| 来凤县| 绵阳市| 上思县| 凌海市| 肃宁县| 贞丰县| 邓州市| 蒙城县| 峨眉山市| 临朐县| 绩溪县| 鄯善县| 砀山县| 玉屏| 铁岭市| 思茅市| 宿州市| 新化县| 苍梧县| 杭锦后旗|