dwyl / dwyl/content

Phoenix can implicitly render responses based off `Accept` header

Open
#7 1 comment 1 reaction 0 assignees View on GitHub
discuss
Dominant language
Elixir
Stars
21
Forks
1
Avg merge
1d 17h
Merged PRs (30d)
4

Description

Phoenix can already implicitly render different responses based off the `Accept` header or through forcing a type through the `put_accept` plug.

```elixir
def index(conn, _params) do
doors = Access.list_doors()
render(conn, :index, doors: doors)
end
```

Will render "index.json" or "index.html" implicitly.

See https://gist.github.com/chrismccord/31340f08d62de1457454.

In the Phoenix Docs: https://hexdocs.pm/phoenix/Phoenix.Controller.html#render/3

Specifically;

> template - which may be an atom or a string. If an atom, like :index, it will render a template with the same format as the one returned by get_format/1. For example, for an HTML request, it will render the "index.html" template. If the template is a string, it must contain the extension too, like "index.json"

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.