![]() ![]() In the client->post() method above, we pass in a URL string, and an array of request options. ![]() $response = json_decode($request->getBody()) Next, let's POST some JSON to a remote API: Guzzle also provides a list of synchronous methods for making requests, a full list is available here: We're going to take a look at some examples using the CKAN API, full documentation is available here.įirst, let's take a quick look at how we make requests in Drupal. Drupal::httpClient in a moduleĭata.gov provides a catalog of data via CKAN, a powerful open source data platform that includes a robust API. The Guzzle documentation is available here. You can check the version of Guzzle that you’re using by taking a look at the composer.lock file in your Drupal project directory. This allows Guzzle to work with any other library that utilizes PSR-7 message interfaces. PSR-7 describes common interfaces for representing HTTP messages. Guzzle utilizes PSR-7 as the HTTP message interface. Drupal and Guzzle (in short)Īccording to the Guzzle project page, "Guzzle is a PHP HTTP client and framework for building RESTful web service clients." ![]() This functionality now exists in Drupal::httpClient for Drupal 8. In Drupal 7, you would have used the drupal_http_request function for sending HTTP requests. This is particularly useful when you wish to communicate with external websites or web services. In this post, we'll take a look at how we can use the Drupal::httpClient class for making HTTP requests in a module. This is simply a wrapper for the wonderful Guzzle HTTP Client. With the release of Drupal 8 comes a new way of making web requests, available via the Drupal::httpClient. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |