2

I have an API which I would like to consume to do specific actions on my Drupal 7 website after getting data from the user via a webform form. I plan to write my own custom module to do that but don't know how where I should start from.

Is there any hook that could help me add supplementary action after getting data from my webform ? How am I supposed to proceed to consume my web services ? Any code snippet, advice, will be appreciated.

3 Answers 3

2

Module RESTClient is for this purpose.

It provides 4 APIs:

  • restclient_get()
  • restclient_post()
  • restclient_put()
  • restclient_delete()
8
  • I successfully tested [RestClient] (drupal.org/project/restclient) with key/value pairs sent for the query as plain text. However, I couldn't consume my RestFul APIs with which is based on XML queries. So my question now is how to use RestClient module to consume Restful API using XML queries ? Commented Nov 1, 2016 at 9:43
  • I guess your problem is how to create xml content with PHP, isn't it?
    – Jimmy Ko
    Commented Nov 1, 2016 at 10:06
  • Yes, it is. And how to use my XML with RestClient. Commented Nov 1, 2016 at 10:17
  • Just put array('body' => $xml_str) as the second arguments in the mentioned APIs. You are better to create a new question about constructing xml content with PHP in StackOverflow.
    – Jimmy Ko
    Commented Nov 1, 2016 at 10:23
  • 1
    @SinanErdem It's documentation is suck. I read its code to find these APIs.
    – Jimmy Ko
    Commented Aug 23, 2017 at 0:02
0

Most would agree here that there is no need to re-invent the wheel. There are already at least 4 wheels here that can be used. The Services module, which also has support for the Webform module (through another contributed module), is the most popular module for this job:

The other big players would be the RESTful module, restws and as Jimmy Ko mentioned, RESTClient. Although I don't personally have experience with these last 3, all 4 will have their pros/cons. Each should have sufficient documentation and code examples in the wild to get you started.

1
  • Most modules you listed here is to create restful service but not to consume restful APIs.
    – Jimmy Ko
    Commented Oct 25, 2016 at 8:13
0

Web Service Clients was the only module I could get to work.

You create a connection via UI. Then you can use the API and make your requests from code.

Example API usage:

// 'my_connection' is the machine name of the connection.
$result = clients_connection_call('my_connection', 'method.name', $param1, $param2, $param_etc);

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.