Elixir plugin: proper way to get form data from post request


username

I'm playing around with inserting a router and trying to read the body of a simple post request in the router :

sheet

<form action="/create_item" method="post">
  <input type="text" value="whatever" name="name">
  <input type="number" value="99" name="age">
  <input type="submit">
</form>

my router

post("/create_item") do
  {:ok, data, _conn} = read_body(conn)
  send_resp(conn, 200, data)
end

If I submit the form it renders name=input-valueto the page, but then I have to parse the string to get the value. This smells the wrong way.

From my little experience with elixir, it seems like I should be doing something like pattern matching on read_body(conn)to extract each key: valuefrom the form , but I can't find anything about this in the plug docs . I'm trying to dig out some ideas from Phoenix Resources, but it's beyond my knowledge of elixirs. Am I missing an obvious function?parse_form_data/1

what to hide

Plug.Conn.read_body/1Just read the body of the request without parsing it. To parse the body, you usually need to use a plugin that reads and parses the body of the request based on the content type of the request.Plug.Parsers

For example, if you insert like this:

plug Plug.Parsers, parsers: [:urlencoded]

Anywhere after that will conn.paramsbe available.

Related


Q: Proper way to post JSON from Reactstrap form

young stupid question god I want to get JSON from a form I've created with Reactstrap to be able to post it to my backend. I found this example. I want to use Reactstrap, so I can't put it onSubmit={this.handleSubmit}on that Formcomponent. That's why I thought

Get form_params data from Guzzle post request in Lumen API

workbench In my laravel 5.7 app, I have a controller with the following method that sends a post request to the lumen api using GuzzleHttp\Client. public function insert(Request $request) { $domain = Config::get('url.gcr_api'); // gcr_api is defin

How to get data from POST request

Katherine I am confused how to get the data from the post request and then send it to the sheet. I don't know how to also confirm with the client. Any help would be greatly appreciated thanks. I'm trying to build a web app that will be a check in/checkout syst

Elixir plugin: proper way to get form data from post request

username I'm playing around with inserting a router and trying to read the body of a simple post request in the router : sheet <form action="/create_item" method="post"> <input type="text" value="whatever" name="name"> <input type="number" value="99" name=

How to get form data from POST request in Java

Freak 09 How to extract form data from POST request eg. $ curl -X POST -d asdf=blah http://localhost:8000/proxy/http://httpbin.org/post - I need to extract asdf=blah. The way I'm doing this currently relies heavily on the data I'm reading in a certain format (

Get post data from ajax request php

Nathan Loudon I keep getting null values with the following code: Ajax request: formData = { u: "3959eeadb32e02b85a792e21c", id: "6d7613df26" }; $.ajax({ url: "/includes/loginProcess.php", type: "

Jersey: get binary data from post request

something I'm trying to build a Java server using Jersey that accepts POST requests with binary data. Here's an example request it should accept: curl -XPOST --data-binary @/path/to/some/file "localhost:<port>/myServer/processMyData" I implemented something t

POST request with form data

Zachary Weeden I'm trying to simulate a request with various headers and bracketed form data. Tabular data: {"username": "MY_USERNAME", "pass": "MY_PASS", "AUTO": "true"} This is the form data displayed in the Chrome console, so I tried putting it together wi

Elixir plugin: proper way to get form data from post request

username I'm playing around with inserting a router and trying to read the body of a simple post request in the router : sheet <form action="/create_item" method="post"> <input type="text" value="whatever" name="name"> <input type="number" value="99" name=

Elixir plugin: proper way to get form data from post request

username I'm playing around with inserting a router and trying to read the body of a simple post request in the router : sheet <form action="/create_item" method="post"> <input type="text" value="whatever" name="name"> <input type="number" value="99" name=

Unable to get form data on POST request

Will Daniels I am trying to get the parameters of my post request. I can send them using JSON and it works (if I take out the type property of BodyParser.json), but the form data cannot be generated. I am using body analyzer middleware as follows. const BodyPa

Q: Proper way to post JSON from Reactstrap form

young stupid question god I want to get JSON from a form I've created with Reactstrap to be able to post it to my backend. I found this example. I want to use Reactstrap, so I can't put it onSubmit={this.handleSubmit}on that Formcomponent. That's why I thought

Get form_params data from Guzzle post request in Lumen API

workbench In my laravel 5.7 app, I have a controller with the following method that sends a post request to the lumen api using GuzzleHttp\Client. public function insert(Request $request) { $domain = Config::get('url.gcr_api'); // gcr_api is defin

Get post data from ajax request php

Nathan Loudon I keep getting null values with the following code: Ajax request: formData = { u: "3959eeadb32e02b85a792e21c", id: "6d7613df26" }; $.ajax({ url: "/includes/loginProcess.php", type: "

Get data from POST request

Murphy POST data doesn't always fit my logic despite correctly updating django models def new_record(request): form = RecordForm(request.POST or None) if request.method == 'POST': if form.is_valid(): form.save() return

Get post data from ajax request php

Nathan Loudon I keep getting null values with the following code: Ajax request: formData = { u: "3959eeadb32e02b85a792e21c", id: "6d7613df26" }; $.ajax({ url: "/includes/loginProcess.php", type: "

Elixir plugin: proper way to get form data from post request

username I'm playing around with inserting a router and trying to read the body of a simple post request in the router : sheet <form action="/create_item" method="post"> <input type="text" value="whatever" name="name"> <input type="number" value="99" name=

Elixir plugin: proper way to get form data from post request

username I'm playing around with inserting a router and trying to read the body of a simple post request in the router : sheet <form action="/create_item" method="post"> <input type="text" value="whatever" name="name"> <input type="number" value="99" name=

Q: Proper way to post JSON from Reactstrap form

young stupid question god I want to get JSON from a form I've created with Reactstrap to be able to post it to my backend. I found this example. I want to use Reactstrap, so I can't put it onSubmit={this.handleSubmit}on that Formcomponent. That's why I thought

Get form_params data from Guzzle post request in Lumen API

workbench In my laravel 5.7 app, I have a controller with the following method that sends a post request to the lumen api using GuzzleHttp\Client. public function insert(Request $request) { $domain = Config::get('url.gcr_api'); // gcr_api is defin

Unable to get form data on POST request

Will Daniels I am trying to get the parameters of my post request. I can send them using JSON and it works (if I take out the type property of BodyParser.json), but the form data cannot be generated. I am using body analyzer middleware as follows. const BodyPa

Get post data from ajax request php

Nathan Loudon I keep getting null values with the following code: Ajax request: formData = { u: "3959eeadb32e02b85a792e21c", id: "6d7613df26" }; $.ajax({ url: "/includes/loginProcess.php", type: "

Get post data from ajax request php

Nathan Loudon I keep getting null values with the following code: Ajax request: formData = { u: "3959eeadb32e02b85a792e21c", id: "6d7613df26" }; $.ajax({ url: "/includes/loginProcess.php", type: "

Get post data from ajax request php

Nathan Loudon I keep getting null values with the following code: Ajax request: formData = { u: "3959eeadb32e02b85a792e21c", id: "6d7613df26" }; $.ajax({ url: "/includes/loginProcess.php", type: "

Get form_params data from Guzzle post request in Lumen API

workbench In my laravel 5.7 app, I have a controller with the following method that sends a post request to the lumen api using GuzzleHttp\Client. public function insert(Request $request) { $domain = Config::get('url.gcr_api'); // gcr_api is defin