Intercept data of a field of a node Drupal 8 How can I intercept the data of a field when the user add's a node?

Below is the use case:

The user can input a address in a field, when the user submits the node.
Drupal should make a rest request to the google maps distance matrix api. Then the returning value should be posted in that node. I can find enough example modules to export data from drupal through rest but not the other way around.
That sounds like a job for hook_node_presave(NodeInterface $node) to me.

That is always called before a node is saved. To optimize it, you probably want to limit your call to only do it for new nodes or when the value changed (compare your field value with the value of $node->original, note that that only exits when updating, so you want to check something like this:

if (!empty($node-&gt;field_yourfield-&gt;value) &amp;&amp; ($node-&gt;isNew() || $node-&gt;field_yourfield-&gt;value != $node-&gt;original-&gt;field_yourfield-&gt;value)) {
  // do your call here, change $node in any way you want and it will be saved with those updated values
}


The same works for any entity type. You could also limit it to running on form submissions, but this has the advantage that it also works in case nodes are updated or created through other ways.