dwyl / content Goto Github PK
View Code? Open in Web Editor NEWπ A Plug to add Content Negotiation to any Phoenix App so you can render HTML or JSON for the same route.
License: GNU General Public License v2.0
π A Plug to add Content Negotiation to any Phoenix App so you can render HTML or JSON for the same route.
License: GNU General Public License v2.0
Should be fixed when dwyl/hits#157 is resolvedβ¦ π
Phoenix can already implicitly render different responses based off the Accept
header or through forcing a type through the put_accept
plug.
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"
Create a file with the following path: .github/dependabot.yml
With the following contents:
version: 2
updates:
- package-ecosystem: mix
directory: "/"
schedule:
interval: daily
time: "07:00"
timezone: Europe/London
Following the instructions in the readme file, I was faced with this error (CompileError) undefined function browser/2 (expected HitsWeb.Router to define such a function or for it to be imported, but none are available)
when adding the content plug to the router pipeline.
The error could be obvious to some but as someone who is starting out, it's not clear in the README that one has to also change the pipe_through
to pipe_through(:any)
in the scope
method inside therouter.ex
file as well.
I can create a PR with this small change to be more clear to a newbie audience π .
As a person using the @dwyl App who also wants to build my own custom interface,
I want to be able to append .json
to any URL in the App
and see a JSON
representation of the content (data)
without having to manually construct an API request.
i.e. use the existing session/JWT and return the data for the given (logged in) person.
Reddit does this for most of their URLs. e.g: reddit.com/r/politics/comments/gpuwml/trump_rips_columbia_as_disgraceful_institution
But appending the .json
to the end of the URL:
reddit.com/r/politics/comments/gpuwml/trump_rips_columbia_as_disgraceful_institution/.json
accept=json
Header if the url contains ".json"
http=>https
We have show that content negotiation is fairly straightforward in a Phoenix App in our tutorial: https://github.com/dwyl/phoenix-content-negotiation-tutorial
but our conclusion is that it's quite cumbersome.
We need a simplified way of doing content negotiation in our App(s)
whereby we only add one line to the router.ex
and one line to each controller.
I think it's possible, but I don't know for sure. π
I would prefer to avoid including Phoenix as a Dependency ... because of maintenance and RAM.
So this issue is a "SPIKE" to:
warning: use Mix.Config is deprecated. Use the Config module instead
config/config.exs:1
Lame.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.