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

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:

主站蜘蛛池模板: 常宁市| 许昌市| 屏边| 定边县| 华容县| 甘肃省| 信丰县| 策勒县| 青浦区| 琼海市| 靖边县| 牡丹江市| 长垣县| 临夏市| 酒泉市| 陵水| 富宁县| 扎兰屯市| 老河口市| 双柏县| 蒲城县| 彝良县| 仲巴县| 黔西县| 大竹县| 雷州市| 萍乡市| 阜平县| 鲜城| 吉木萨尔县| 扬中市| 沾益县| 峨眉山市| 衡东县| 廊坊市| 石嘴山市| 桂阳县| 依兰县| 祁连县| 漠河县| 雅安市|