When you build public facing APIs, there are operations that could not fit enough into request-response cycle. Especially, when it involves user interaction.
Take an example of sending email. You can expose an API endpoint for clients to send email. But whenever the email is opened, the client want to do some action. They can keep polling you and get the status of the email of course. But, that’s suboptimal on both sides. So you want to tell the client when the email is opened. Now, that’s when you do webhooks (ref).
Webhooks are easier to build. After all, it’s just one http call you will have to make.
But, testing it is not so.
Public URL: We need the webhook URL to be accessible from the application server. For local testing
localhost would do. But when you want to test the behaviour in CI ot other enviroments, it requires to be a public URL.
Recorded requests: Once the application is invoked and it called the webhook URL, we need to assert on the request made by application. So we need a way to record those requests and assert later.