-
Notifications
You must be signed in to change notification settings - Fork 51
Open
Labels
bugSomething isn't workingSomething isn't workingdocumentationImprovements or additions to documentationImprovements or additions to documentationquestionFurther information is requestedFurther information is requested
Description
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
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingdocumentationImprovements or additions to documentationImprovements or additions to documentationquestionFurther information is requestedFurther information is requested