0

I am really new to Drupal but I have to do a project using it and I was just wondering how to handle an incoming POST request in a module:

I am creating a module that will get incoming data from a Webform, process the data by running an R script on it, and then return the result of the R function on the data to the url path specified in the module, but I am not sure at all how to begin handling POST requests - can someone give me some insight? In Webform settings you can specify a URL to send a POST request with the form data upon submission, but if I can figure out how to handle that data I will be golden!

3
  • What version of Drupal are you using? Also what webform config was it that allowed you to post to external URLs? Are you familiar with handling POST using some web technology? Which?
    – anoopjohn
    Commented Nov 7, 2019 at 5:51
  • It is Drupal 8.5.4. The functionality to POST to a URL is built-in to Webform, you can access it in the settings of the form you are building. I have extensive familiarity with handling web requests using Python and Javascript
    – T Kharel
    Commented Nov 7, 2019 at 6:13
  • Thanks. I didn't know that :). I have added a couple of links in the answer below on how you can start with this. Hope that helps.
    – anoopjohn
    Commented Nov 7, 2019 at 6:40

1 Answer 1

2

If posting to external URLs is allowed, and given that you are not familiar with Drupal, you can post that data to an external URL where you can write a script using the language / framework you are familiar with and process the data. Especially since you are only looking to process the data with R.

If you want to manage your processing within Drupal itself that is also doable. You will have to write a custom controller in your module, add the route in the module.routing.yml file and then handle the POST data in your controller.

Here are couple of places you can start

https://www.drupal.org/docs/8/api/routing-system/introductory-drupal-8-routes-and-controllers-example

How to get $_POST and $_GET parameters

3
  • Thanks for the feedback! I unfortunately cannot use an external website - I was hoping to POST the data to a URL that is handled by my custom module.
    – T Kharel
    Commented Nov 7, 2019 at 6:14
  • Is the objective of the project about the analysis or doing the analysis within Drupal itself?
    – anoopjohn
    Commented Nov 7, 2019 at 6:33
  • Drupal can of course handle the post in the custom module. You can create a custom controller in your module, add the route to the controller into module.routing.yml and then handle the POST data in the controller class.
    – anoopjohn
    Commented Nov 7, 2019 at 6:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.