HTTP communication

HTTP protocol (Hypertext Transfer Protocol) – used in a browser window, preceding the address of a web page. It often goes unnoticed and is simply bypassed by Internet users. However, even when you type the address itself, the http protocol (and https protocol) appears automatically. It allows client-server communication. Hypertext Transfer Protocol determines how content is shared, transformed and how it is to be read by the server.


An example HTTP link might look like the following:
https://api.deante.pl/api/products?key=API_KEY&lang=en

  • https:// - https protocol means connection is encrypted with SSL certificate
  • api.deante.pl - website domain - this is the address indicating the place on the Internet
  • /api/products - internal path in the domain - points to a specific resource
  • ? - question mark starts passing additional parameters
  • key= - additional query parameter - before the = character there is the name of the parameter
  • API_KEY - additional query parameter - value of the parameter named key
  • & - additional query parameters are combined with the & character

Downloading data via HTTP

cURL - downloading via system console

To receive data through HTTP we can use the cURL library. After installing it on our computer, we get the ability to perform queries from the system console. All we need to do is to type a properly prepared command to get data from the server.

curl https://api.deante.pl/api/products?key=API_KEY    --output deanteProducts.xml

cURL - downloading data in PHP

The cURL library makes it possible to retrieve data not only through the system console, it can also be used in a PHP application. The data downloaded this way can then be read into the product database in the target sales platform.

$curl = curl_init();curl_setopt($curl,     CURLOPT_URL,     "https://api.deante.pl/api/products?key=API_KEY");curl_setopt($curl, CURLOPT_FAILONERROR, true);curl_exec($curl) // Execution of the request if(curl_errno($curl)){    $errorMessage = curl_error($curl);}curl_close($curl)if(isset($errorMessage)){    // Error handling (e.g. temporary server unavailability or wrong API key)}

Axios - pobieranie danych w NodeJS

The axios library allows you to make queries directly from your browser or Node.JS application. The data retrieved by Axios can then be loaded into a product database in your sales platform.

import axios from 'axios';try{    const response = await axios.get(        "https://api.deante.pl/api/products?key=API_KEY"    )    // The downloaded product data is saved to the response.data object    return response.data }catch(error){    // Error handling (e.g. temporary server unavailability or wrong API key)}
Last modifed at : 2022-12-28