-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create Content Negotiation Tutorial #1
Comments
Seeing this error:
Will investigate when I get back to my desk. |
Derp ... 🤦 defmodule AppWeb.PageControllerTest do
use AppWeb.ConnCase
test "GET /", %{conn: conn} do
conn =
conn
|> put_req_header("accept", "text/html")
|> get(conn, "/")
assert html_response(conn, 200) =~ "Welcome to Phoenix!"
end
end If you can, great! If not, don't worry, it's subtle! See the commit that fixed the test: 7fc61bc |
I'm fairly happy with the tutorial: https://github.com/dwyl/phoenix-content-negotiation-tutorial Now I'm working on generalising the solution in a Plug so that any App can do this with minimal code: https://github.com/dwyl/content_negotiation_plug 🧑💻 |
Our goal with the @dwyl App is to have a server-side rendered (and progressively enhanced) Web UI (
HTML
) that works on any device and a REST API (JSON
) that can be consumed programmatically by any script/system/app. We want thedefault
UX (the Web) to be great and we want the API to be available from "Day 1". We definitely don't want to create/maintain two separate Phoenix Apps. We don't even want to maintain two separate router pipelines. We want the same route to transparently return a different representation of the content dependent on theAccepts
header.Todo
GET /
request.HTML
if theAccepts
header istext/html
JSON
if theAccepts
header isapplication/json
Read and understand the following:
The text was updated successfully, but these errors were encountered: