Back to Blog List

Netlify Hooks

For static sites we want the site to rebuild depending on a certain actions such as saving data in a database. In order to do this we need to first setup a webhook. With Netlify this is is really easy. Once your site is setup and running on Netlify just go to the Build and deploy section of your Netlify account under the settings tab and then scroll to "Build Hooks".

Click on the button "Add build hook" and give your hook a name. Choose the branch you would like it to use, master for production or dev for testing for example. Netlify then generates a Netlify build hook URL. This is all you need as Netlify will take care of the rest by triggering a build and deployment of your site when this hook is callled.

Netlify Build Hooks

We now need to trigger this hook when we change our content in our api. With Hasura as our backend it is really easy to set up this trigger. Once your api has been created and you have a table you just need to go to the Events tab and click on create. Give your event a name. Select which table you want the trigger to apply to and then choose what operations, insert, update or delete. Now we just have to paste in our URL we got from our Netlfiy build hook and press "create event trigger".

Hasura Event triggers

And it is as simple as that. Now when we make content changes in Hasura, on the table we created the trigger on, it will trigger the Netlify build hook and our site will be built and deployed automatically.

And we can see it worked not just by checking the content on our site but also in our Netlfiy admin panel under deploys where we can see what triggered each deploy.