Note: If the port is non standard (not 80) we need to include it after the url using the following format: You should notice we are expecting the webserver to return a UTF-8 string i.e. The simple flow shown below uses a GET request to request a web page from the jsonplaceholder site. The output of the request node contains the response from the web server.
Quick node http server code#
To do the same in the function node then add the following code to the function node. This tells the server that the data being sent is JSON encoded data as is a common setting when working with APIs.
Quick node http server how to#
The screen shot below show how to set the content type to JSON.
You can use a function node or change node to set the request headers. HTTP requests contain http headers these cannot be changed in the node but must be set in a preceding node if they need setting.Ĭommon examples are setting the payload type when sending JSON data in post messages. You can then use a function or change node to set the method and url by using the msg.method and msg.url properties as shown below. To do that you must configure the http request node request method to be set by msg.method and leave the url blank as shown above The request method and the url can also be set in the node or a proceeding node. The node will convert JSON data into a JavaScript object.
The request method -The node supports the GET,POST,PUT and DELETE methods.Note: if you are not familiar with the http protocol then I suggest you read the http basics tutorial.īelow is a screen shot of the http request node configuration page. The node handles both the request and response. The node will send a request and receive the response. Sending and receiving JSON data to a website or API.http request – used for making http requests i.e an http client.http response – used with http-in to send responses.http-in -Used to configure a web server.