# Super powers of the Webhook node - Ben Hesseldieck

## Метаданные

- **Канал:** n8n
- **YouTube:** https://www.youtube.com/watch?v=tb9kUgOfHCw
- **Дата:** 28.06.2021
- **Длительность:** 11:15
- **Просмотры:** 1,545

## Описание

In this talk, Ben shows us the dynamic route feature of the Webhook node and how to use it to build APIs in n8n.

## Содержание

### [0:00](https://www.youtube.com/watch?v=tb9kUgOfHCw) Intro

so um we we're getting now a bit more technical i mean i'm one of the engineers at ntn so um that that's my passion um yeah i'm not an infrastructure expert or anything we're just like doing um yeah we just want to improve the product and then build it away on the requirements that we have so there's definitely things that you can always do better or so on so just as a disclaimer so we because i'm gonna tell you know how we solve one of the problems that we're

### [0:31](https://www.youtube.com/watch?v=tb9kUgOfHCw&t=31s) Disclaimer

having and um the problem that we had is that people were just able to use static round smallers i mean you had the option to use params or on the post you were able to put something on the body but you were not able to post like data within the route and we had a lot of requests from the community that exactly needed this feature because they wanted to integrate with another service who was for example sending the id in the route and there was no option with how you can handle this right and um this came with a lot of

### [1:03](https://www.youtube.com/watch?v=tb9kUgOfHCw&t=63s) Requirements

requirements because like we're not building on a green field anymore it's like um yeah we're working on we also one don't want to break any existing uh containers or instances so um first of all we want to support wild cards at any position in iraq because we don't know what users need right we don't know uh what they want to send what like maybe others api needs to send so it needs to be at the big it can be in the beginning it can be the only thing but there also can be static parts within it and um yeah there's still like static parts needs to work for example as we're having like product one because like some people are already using them and maybe having numbers in there but at the same time they want to use a white or use a white card at the same position more or less that so making it flexible for the future but maintaining their old web hook that they are already having in use right and then um we also want to pass them in a cool way to the workflow so that people can easily access them so that you are when you're defining the route your mall is giving the key and then our system and it ends parsing or whatever is in there in the route and gives it back to you and yeah and also we want to keep the same route stem the people of you who already built an api know this so there's like always for example if you're working on a user usually you start with user and this way you create it and if you edit it then you're using user slash id like i know 50 10 whatever and so on and there's like certain um standard smallers that we still wanted to maintain and want to um when she preserved to really give like an api like feature feeling and there's also some internal stuff that's going on so um yeah we want to keep me in it and stay scalable and this meant we can just use the database more or less because um as you know maybe from the scalability talk from omar already where you can spin up multiple workers and they are working independently and the only common ground that they are having is our database right and so this was the only possibility that we can use um to save any data and make any decisions based on and yeah now i want to show you

### [3:27](https://www.youtube.com/watch?v=tb9kUgOfHCw&t=207s) App example

how we've built our new pokemon train app and i know i'm a developer i'm still using postgres we could also use airtable but uh it's simple so please uh no fears here and for example let's start with our pokemon trainer so as i already said like usually you have a stem in an api which is in this case the trainers and um then you have like an id or you could even call it trainer id or something and then you could like get his pokemon for example right and this will be one route or uh the most basic rule of just getting all trainers right just like you should be able to be called and um as we can see okay i wanna run it now on test then we're running get all trainers here and when we're running it as a test i'm gonna send it here slow for whatever reason there we go we have ash misty and brock so all three trainers that we're having in the database if we just wanna have get a specific trainer now comes our first case where we want to have an id right so we're hitting trainers and then we want to have an id normal simply get um we have this now so i don't always have to run the execute i built this like with activating the node and then there we go um there's one thing changing and you might have seen this already when you're using um when you're using white cards uh i don't know maybe i can zoom in so when you're using white cards you see that we have like this id in here that's necessary for us because we need it from a technical perspective and technical standpoint if you want to have this also for your static routes um this would mean that you would need to copy this id and insert it beforehand if you need to have exactly the same url if you're building your own app and you can define the route you're free to do whatever you want so yeah as we're sending it here we also want to get uh the pokemons of the trainer right and here we have it for example nested within the query like the id is in the middle of it and then we want to get the pokemons and yeah i mean we can just test it so we see it running and run it here we want to get the pokemon of the trainer and for example we can get the pokemon of ash which is like id1 it's running there we go we have pikachu level six pokedex id number 25. so pretty easy there but like as we know like our apis are not just like getting data it's like also creating and updating data and for example we want to create a pokemon for example niran i don't know maybe someone's um favorite pokemon i just chose it like by accident more or less here i have a beautiful list okay of all the pokemon that we can choose so we can also like later on if we got some time uh we can get deeper into this but here we just want to create one and um so here we're just sending like a post to the normal pokemon so it's again the simple standard one it's not breaking anything well then so we now created number 32 neutron but now we want to capture a pokemon right and uh we think now ash is the right guy to capture our nidoran with like our id 32 because like when we are looking at capturing a pokemon we see that we have to train our id here at the second position and the pokemon id at the end with like a capture and the trainers in between so like a normal api and we're just moving it here like there's the one and the 32 and then we're catching it and when we're getting back hey to the pikachu now we have a net level one nidora level one is pretty weak and you can't do much with a level one neither up i mean even your level two taupsy will probably make you a lot of problems so what we're gonna do we're gonna level up our neura and this is pretty easy as well because we know the trainer id we know the pokemons around we know the pokemon id needs to come afterwards and then as we designed it uh we just need to add to the body the level so what we're doing we're going into our route we can add it like our neither run and because we know it's a powerful need around and um yeah it we never let it evolve so that that's why we are now bringing it up to level 55 and then we're seeing hey we get back our need run level 55 we can check all our executions as usual in here up i need to finally find this yes we want to switch and here we see

### [8:28](https://www.youtube.com/watch?v=tb9kUgOfHCw&t=508s) Postgres

for example that our level up run here we're just setting some data writing it into postgres and to see that i'm not lying i for sure also have my pokemon database available so you see all captured pokemon these are the trainers like id1 is ash 82 is misty so he has like his neither on with like id 32 in here and level 55 and that's where we have it and this is now this morning simple path like how you can build like a complete api when i remember the pa the times where i have been building apps it was like mainly crowding users or cutting data um what you can also do oh that's also what i wanted to show um i mean for example if this is not doing the job for you can as easy as that like um let's just open it again what we can do always is just like for example dropping in another function no oh not what i'm doing here for example and if we need to run some some logic or so on like i mean we can always change it and work in it and this makes it really powerful i mean it's like i've built this api faster than i would probably build it in code without like all the setup and so on because like spinning up and in just like running one darker container so that's super amazing there and yeah um i can like get also into some more technical

### [9:58](https://www.youtube.com/watch?v=tb9kUgOfHCw&t=598s) Technical details

details how we did it um we unfortunately need to prefix the webhook id in front of the route to have like an identifier um we can maintain the older behavior because of this because we're just adding to the route and now um it's like uh our idea now is that we're using the web hook id in combination with the whole length of the path that you're typing in and this smallest our identifier which really like allows us that we can match the route uh exactly um the params that you're passing in with the right keys so that your workflow's starting correctly as you see here for example this middle part is like this long middle part and middle is just the id and then it is like all the easy part that we know cool and just as last comment i put now everything into one workflow and as you know with an end you're so flexible you can spread it over multiple workflows if you have one to have like one workflow action no problem you only thing that you should do is like copying um the workflow over so it maintains the id um just as a hint and otherwise uh yeah the sky's the limit i would say you

---
*Источник: https://ekstraktznaniy.ru/video/15796*