Absolute beginner with Node-RED: Today define a REST endpoint (REST API) with the "HTTP in" node.

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi today is sunday and i thought by myself yesterday i created a video about code engine and i thought today it's time for a new node red absolute beginner live stream and yeah i do that because i was asked here to do more videos related to node red and yeah i thought today it's okay i will create one and uh one related to an topic which uh it's a little bit challenging for absolute beginners and um it's about understanding rest endpoints and i don't want to talk too much about the technology and the rest endpoint itself it's more about to get the job done inside not read and if you want to check out more about existing topics i i have with node-red absolute beginner i already put below in the description links and now we start with that here that's the flow absolute beginner and in one of the last videos i created a flow which consumes external rest api this was given here and now today i will uh yeah i see someone say hey hi i say i say hi yeah uh in the chat so it's a little bit delay because i have the buffer with um yeah with normal and so i cannot if you do an uncomment i cannot directly respond yeah so relate to my internet connection okay so i now start with the topic um building a rest api and building a rest api or more or less rest endpoint first is you have to understand here when i go here http in so what is a little bit challenging what i notice when i uh do that that the people want to trigger that uh inside the node red flow when we talk about providing a rest api yeah it's not that you can trigger it from inside your flow yeah you will invoke it from external or from inside your node red but with an http request but that's later so first we need an http in and then is here the http response so and uh between these two things here we will wire uh yeah or there happens what we want to provide to the external per persons or systems here what information we want to provide and in that case i just use here a function here so that is what we will do he will here uh define how it can be invoked so and i i just write here very very simple it's not it's just to understand how it works get name here so i say here get name and i deployed and then with that i can say for example when i go into the function here is the message object for the return value and i will now create a variable which is called i call it payload yeah you can call it as as you want yeah and this is uh just for jason yeah later i will add some json information there and i will write here because i i will extend it later a little bit i just write here here payload again yeah and then i say here the payload will be here i call it uh what is it i call it a message yeah and everyone likes just to say hello world yeah very simply yeah so okay that's all yeah you can see and now we need to uh define that these um object or this variable the value is also fine for our message object we use here inside another so then we define for our payload uh payload here is payload okay so now understand what happens what we have done and uh for sure what i always saying yeah it is always good uh to use in debug node yeah so that we can see what happens here when we invoke it from external yeah so then this was uh or this is when it will be invoked here what will be sent here and here we will see what we will provide and then i say deploy and here you can see uh once again here that is how we defined our rest endpoint here so there are different possibilities when you define rest endpoints i only use the get in that situation that's the simplest one but you also can post information put and delete but if you want to dig into that there are a lot of other videos also but i think that's a good starting point really to understand here in the node-red world yeah how it works so okay you can see here that is our endpoint here that's a different definition with get name and now how do we invoke these endpoint um we simply can use that when we just copy the url okay so here's a and we insert url and we say here get my so you can see here this here is hello world um but i want also to show you if you have more later on more complex invocations usually is used to check it out there's postman so you should know postman for for that here you can download postman for free here configure it i already have here one postman and here i will add uh a request to my collection so that's the ui postman it's a newer ui yeah i installed it today once again so i noticed yeah so some things are changed they are they are frequently involved yeah so and i now create a request here we just insert what we inserted here so that is our request so we can say you can also save it and you can say the name is this simple request some request here save say send so you can see here also hello world here also very simple and you can see the headers here what's hidden yeah this is later if you really dig into all that topics with um rest endpoints and http requests and really api so then this is what you will need to understand here so as i said that's the first step so with that uh we take also a look into our debug window and we can see in here in our debug window yeah first of all there was an empty message here there was nothing here because it's nothing additional sent here so and that is what our function provides and you can see that was one was invoked from here and the other was invoked from from there so what i frequently uh suggest take the advantage of the descriptions here of the documentation here here is the documentation you can see and um when you work with endpoints with that http in node understand what is a body what is a header query parameters and so on yeah so and with that in mind here we will do the next steps i want to show um to make this a little bit more not a lot a little bit more flexible so that we use a parameter for our for our request so that means here we will expect later yeah so as we see here what is written in the documentation we will see uh the payload we will say if the message payload will be first name here and i say here my name is thomas and i said yeah first name is thomas then okay so we turn then we will define our payload content hello world yeah greetings thomas so that's uh what happens when thomas is first name yeah man it should be name and then here you don't want so here and else it remains like it is okay so when we deploy that now we will not change a lot not a lot we will not change anything here what we now utilize that the person here who will invoke our endpoint has to know how to invoke the endpoint itself yeah so and with that we go to the uh the postman and that's the reason why uh postman is is very good so i i say here there's a question mark here and then i say here there's here first name and then i say here the first name value that's parameter and the first value is thomas okay so and you can see it always it also already extracted that as parameter very parameter here for um for that request so and when we send it now so we can see here hello world greetings from thomas so we can save these as a new request you can see uh right that is a simple request with very little okay so we save it into the notepad so and then then it's very simply then you can directly select it here yeah and you have it now when you open up uh your postman you can check it out you only have to replace here the urls and uh it that's that's very useful yeah so now we are yeah we are fine with that and now you see and that is a little bit what for new programmer or a new user in inside a node-red what is a little bit strange is ah yeah how to trigger that yeah you do not trigger it inside you provide an external rest endpoint api and just for it just to say api what makes the api more compliant to api is also a naming convention and here we used get name and normally yeah you you say here api yeah and then you ought to say um or provide information about the version yeah but i don't want to uh go too deep in all these stuff and just that's a little bit preview yeah when you dig into these topics really writing apis and so on and what i also want to highlight now when we are starting with that you come into the situation or you will come into the situation that you have to take care about cross-origin regions and that means when you request when when you use these api then it could be that it is not allowed that you use it inside a web application that is what normal what usually happens when i provide work in hackathons that they cannot invoke it in you know only in the ui yeah so and that is what i do not currently cover i also created a blog post about that when i go here there was a of course you can see here then we come a little bit more into the programming stuff there are several possibilities to do that there's also a possibility to have some settings but i don't as i said i don't want to to start to dig in all that in in other topics here so and what i now want what i what we did what the objective is of that short um live stream yeah sunday live stream yeah entertaining is yeah how do i invoke it now internally from my red flow and then yeah then i really can trigger the input invocation and now i will use here the http request and you can see here there's a possibility for the import and you know here the http rest endpoint you know huh maybe it reminds you to one of the last videos yeah and then we simply uh do um also an eject node yeah then we can start it you can trigger it from here so i can yeah it doesn't matter because it uh we can we currently do not use the information input yeah and then we can copy oh here's that into the url here you remember maybe when you have seen the the last one that is really for the invocation of external endpoints and so the external endpoint here is not really external for us it's internal but we have to invoke it to the internet and that is uh a little bit tricky at the first time to understand here huh it's insane but i have to i cannot regret yes and that is uh what you have to understand yeah so then uh i would like to say here with a comment okay here's the comment that's our rest endpoint end point okay that's the rest end point you can invoke and um i would see here the debug black one also you know how i like this debug so that is our output here and rest and quiet okay so with that when we have that yeah um everything should work so let us check it out take a look here i will clean it up and now i invoke it and you can see what happens here first here remember is empty because you know here we do not have an um in parameter so that's empty when we uh use it from here with the parameter the same you can see that it was empty and this was the input from the from the postman so back so i clear it once more to make it obverse so here i invoke it here it's empty here on the debug no information so uh it provides the information that message yeah that is here the output and that is the information we got from here from the internal flow blood we invoked it to the rest end point and what i also will do what you have seen maybe also in the last video is uh the the frequent normal exchange of data is used in json and that is currently not injected again that's in a string yeah and in that format what is given here so it's um and with that i can use here json and just for the formatting yeah so and here once again right here once again now you you can see there here was it that's text and that's an object we can use later yeah and that at least was all but i guess that is really uh critical uh or is important to understand if you are a beginner i would say yeah that's a little bit challenging really understanding uh an endpoint and how to invoke that and um yeah to understand that that's i would say that's the really the basic to understand what i also wrote and i i i can encourage you because i like yeah i did it i like it for sure twitter so i created a flow it's called twitter follower and that flow contains a lot of uh content with really usage and also i do the they're also authentication stuff yeah um and uh the two level or the o out uh authentication with twitter so i can get the api i get an api key from twitter and i examine yeah followers so and yeah that's more in-depth yeah it's not no longer it's it's not totally complicated but it's i would say it's more than a beginner yeah and yeah i would say yeah yeah i did it i can't say hello you have seen it hello so here is uh greetings for the live stream okay so um i would say uh that's that's all at the moment yeah and i would say it's sunday yeah i thought yeah by myself oh yeah take the time do a short video about that um i would say it's an important topic and if you have liked it yeah you can subscribe to that and give me feedback maybe what you're also interested in and i say thank you very much and have a nice sunday wherever you are and maybe see us in a accidentally live stream or at the video i do or i will do okay i say bye and now i have to find the streaming button again and i say hey bye the streaming now ends have a nice sunday
Info
Channel: Thomas Südbröcker
Views: 1,115
Rating: 5 out of 5
Keywords:
Id: wk7dnNA01hM
Channel Id: undefined
Length: 26min 0sec (1560 seconds)
Published: Sun May 09 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.