Skip to content
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

building-apps-with-plug-router need to set content-type for json ?? #195

Open
tomsawyercode opened this issue Jun 22, 2022 · 1 comment
Open
Labels
bug Something isn't working documentation Improvements or additions to documentation question Further information is requested

Comments

@tomsawyercode
Copy link

tomsawyercode commented Jun 22, 2022

I am reading the next article:

https://elixirschool.com/blog/building-apps-with-plug-router/

In the render_json function the content-type is not set
so only receive a raw string.

Then the code must to include the content type:

  get "/getjson" do
    jsonmap = %{key: "value."}
    {:ok, str} = Jason.encode(jsonmap)
    send_resp(conn|>put_resp_content_type("application/json"), 200, str)
  end

Also how can monkey patch or add a function to Plug.route
that can be available in all my routes just doing: use Plug.Route or use Plug.RoutePatched

so can use:

send_json(conn,200,map) # for "application/json"

or another for binary->

send_binary(conn,200,buffer) # for 'image/jpeg'

send_attach(conn,200,filebuffer,"filename")#for "content-disposition", "attachment; filename=myfile.csv", to use in CSV,ZIP etc..

Greetings

@doomspork doomspork added bug Something isn't working documentation Improvements or additions to documentation question Further information is requested labels Jun 26, 2022
@doomspork
Copy link
Member

Hi @tomsawyercode! Thanks for bringing this to our attention. This is a good call out and something we should change. I'm happy to make the change or defer to you if you'd rather 😁

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working documentation Improvements or additions to documentation question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants