Skip to main content
Webhooks and callbacks are both mechanisms used to enable communication between different systems or components in software development, often for the purpose of executing code in response to specific events. However, they operate in different contexts and are used in different ways.

What are Callbacks?

Callbacks are functions that are passed as arguments to other functions or methods, and they are invoked (or “called back”) after the completion of a task or operation. Callbacks are a common pattern in programming, particularly in asynchronous operations, where you want to execute a piece of code after a certain task is done without blocking the main execution thread.

What are Webhooks?

Webhooks are a type of callback that operates over the web, allowing one system to send real-time data to another system as soon as an event occurs. Unlike traditional callbacks, which are typically defined within the same codebase or application, webhooks are used for communication between different applications or services over the internet.

PDF.co & Webhooks

The webhook or callback endpoint must respond immediately within a few seconds. If the endpoint does not respond within 20-30 seconds, the PDF.co API considers the attempt failed and will retry the callback up to 3 times.
Webhooks can be utilized by setting the callback object with the URL of your choice, which triggers a POST request to the specified webhook URL upon completion of the job process.
{
    "callback": "https://example.com/callback/url/you/provided"
}

Basic Authentication in Callback URLs

You can specify Basic Authentication credentials directly in the callback URL like this:
{
  "callback": "https://<username>:<password>@example.com/test/"
}
If your password contains special characters (like @, :, or /), be sure to URL encode them.

Example (with encoded password)

{
  "callback": "https://myuser:my%[email protected]/test/"
}
This is useful when the callback endpoint requires HTTP Basic Authentication. The following APIs accept webhooks:

Summary

Callbacks are functions passed into other functions to be executed after a task is completed, commonly used within the same codebase. Webhooks are a type of callback that operates over the web, allowing one system to send data to another system when a specific event occurs, typically via an HTTP POST request. In essence, webhooks are a practical implementation of the callback concept across different systems, facilitating real-time communication and integration between web applications.