Webhooks aka Reverse APIs

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
what's going on engineers so you've heard about this webhooks thing but you have no clue what it is well you're on the right video its most basic form web hooks are nothing more than HTTP messages that are sent usually in a response to some event from a third-party service that you're using they're also sometimes used to describe pre-built API endpoints that you can use to send data to web hooks and api's are so closely related that sometimes web hooks are called reverse api's because they solve a very important problem with api's for api is the user like you and I will request data from an API and that API will give a response a common use case for web hooks is when you're interested in data the changes so imagine you're writing an application that uses the github API and you're requesting information about the commits for a given project part of your application is you want to perform some action once there's a new commit on that project getting that data from github is not very hard you simply use their API and then you get a list of all the commits for a given project so in this case you could record the hash of the last commit and then just run it over and over and over and over again and just keep checking to see if that hash changes if it does change then you've you know there's a new commit and then your application can respond you know as it should there's a couple problems of doing it this way number one it's complete ways to ban within server resources but number two and this is more important is that github has a cap on the number of API requests you can do so now enter the world of web hooks where you can just tell github when there's a new commit send me a message in this way is no extra bandwidth no extra API calls and there's no limits you're gonna hit so I'm using this web hook tester service which gives me a URL to send my response to so one thing you do need is a place to send the web hook to so in my case is just the tester so I can simply go to settings for my repo and go to web hooks I can add a new web hook you can paste that web hook you know test URL I can say give it to me in JSON Nabal SSL send me the whole push event add a web hook now we're done so you can say the hook was created we sent a ping payload so come on over to our tester we see the we did get one post request from github with a little little phrase here github bookshop so I'll just delete these it's now all we're gonna do now is just make a commit on this on this test repo I have so I'll just do a vent and you'll see when I push this and go back to this window and this will happen every time I make a new commit so if I go just redo it just reach you'll see a new one shows up here I can click that and I get that new commit now the information that you get in the web hook is going to be described ahead of time by the vendor that you're using so in this case github will tell you that in the web hook we're gonna send you you know all this stuff commits and hashes dates and whatever else they want to send but if this were say like a credit card processor maybe they would send you a web hook for a new charge which would contain you know how much the charge was who made the charge and so on remember I said there's the second type of web hook where it's a pre-built kind of Approval api endpoint and you can use that to send data to well one example that is discard web hooks usually when services play nice as one another you're able to send web hooks from one service to another to attain some new functionality on the other service so imagine I wanted to post in my discord server every time there was a commit to a project on github this would be really easy to do I could go into discord under the web hook section I can create in your web hook I can say where I want to post it and then I can take this URL for the web hook and I can save it I would then take that URL and I would put it into github so I can add a new web hook I can use my discord URL discord wants you to put github at the end that way they know it's from github and they can do something fancy with it set application JSON send me everything add web hook and we're all set now that my web hooks created I have a connection between github and discord and I can now make a commit so I'll do a commit message like really hope this makes it to discord and I can do a push and once the push succeeds you can see it popped up over here github one Nukem it really hope this makes it into discord keep in mind that it's not always this easy to integrate two services together the reason this works is because discord has already looked at github webhook format and said if you put slash github at the end of the of the web hooklink discord will be able to parse that message and then make something nice on your server any service that you use that has an API is most like you're going to implement at least some web hooks and that's because there's always going to be data that the user needs to subscribe to oftentimes the data you get from a web hook is the same thing you get from an API it's just you're getting it pushed to you rather than pulling that data from an API in fact the engineer Mann Knowledge Center actually has a web hook right now it's not it's it's only used internally but when a new questions posted there's a message that's sent over to Felix and Felix post that into the e/m KC discord Channel however that can very well be a public feature as well you know MKC you could offer up a web hook for people if they want to be notified of a new question on their own platform something's gonna go over some additional use cases for web hooks so like JIRA has web hooks so if somebody creates a new issue you can push a message over to maybe slack or or wherever email services might have a web hook for notifying you of somebody who won't subscribed from your emails or perhaps they hit the spam button you know their system could notify you of that CRM platforms might have a web hook for when a new lead is added to notify all the sales members of course get help in bitbucket they both implement web hooks for roughly the same thing for new push branches new push commits and so on like an uptime or server monitoring system might have a web hook that pushes a message to slack or somewhere else the big takeaway here is that web hooks are the the necessary supplement to an API because api's themselves do not handle event and that's web hooks hope everybody understands them better now so get out there and start slinging events all over the internet as usual let me know in the comments if you have any questions and I'll see you in the next video
Info
Channel: Engineer Man
Views: 131,236
Rating: undefined out of 5
Keywords: webhooks, apis, engineer man
Id: rUaDIH5ZXB8
Channel Id: undefined
Length: 6min 28sec (388 seconds)
Published: Sun Oct 07 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.