Mini lesson regarding coding, this time about testing a webhook using curl.


We're using Mux for video processing at Crash. The way this works (roughly) is:

  • Us: "Hey mux, we’re about to upload something."
  • Mux: "Cool, here’s an uploadId you can use to create a presigned upload URL"
  • Us: create presigned upload URL
  • User: uploads/streams to this presigned URL
  • Mux: transcodes to high performance web asset as soon as the first bytes come in. Assigns a playbackId once the transcoding is ready.
  • Mux: "Your video is ready for playback!" (webhook)

We were dealing with a small bug though, on our side, as a result of a race condition:  two separate calls in this sequence that are really close together (less than milliseconds apart) sometimes collide with each other.

The fix for this is not even that hard, but the problem comes in when trying to test the solution, seeing that I can't expect Mux to now send webhooks to my localhost.


There are services that can actually channel webhook calls to your localhost (e.g. ngrok) but a way easier solution is to just mock the call by using curl.

cURL (client-url) is a command line interface with which you can send http-requests to any url.

A curl request always starts with curl and ends with the target domain (e.g. http://localhost:3000). You can add data to the request by using the --data or -d flag. A simple curl request could look like this:

curl --data “price=99” localhost:3000

In our case though, the webhook call comes with a JSON payload, in which case you need to add the --header flag saying "content-type: application/json".

curl --header "content-type: application/json" --data '{"type": "video.asset.ready", "object": { "type": "asset", "id":"B02dgt87Jv00mR3cpgcYtOZkIGz87aIZl9"}}' http://localhost:3001/webhooks/mux