Rock U - Lava - Web Request Command
Transcribed Video Content
Often, the data you're working with in Lava already exists in your Rock database, but sometimes you need external data, and this is something you can do to really extend the power of Lava, and that's using the web request command. This command allows you to use an HTTP request to talk to an external API and you can bring in live information from other services. So let's look at the simple syntax you can use and some examples of how we can use it in Rock right now. So for the web request command, it is super powerful and it's a really nice way to make different kinds of requests, kind of a REST or an HTTP request. And it's pretty basic.
You just use a web request and it looks this. There's a command. Here's the opening part. We just say web request, and then we have a basic parameter of URL where we're typing in the URL that we need for to make this request, then we close it off. And within it, within that command, can filter through the results.
Usually they come back in some sort of array and we can output those results whichever way we want to using Lava. Then you'll want to just add end web request on the end. And if you don't know what the structure of your results are, we suggest just using the toJSON filter inside of a pre tag. And that will show you exactly what that array looks so that how to output your results. But let's look at a real example here.
So this is using the Open Weather API, which is a very famous API just for getting the actual weather in a location. We're looking in Surprise, Arizona and we just have a simple URL parameter here with our app ID and we're using some HTML to output the results that we have. And we have some simple lava merge fields that are utilizing that data structure we got back from the API and we're outputting those things such as we have results, weather, main, temperature, humidity, speed. So this will look different depending on what the data structure you're working with is. But I'm gonna exit here and you'll see we're actually pulling live weather for our location of surprise.
It says here, the weather, temperature, humidity, wind, and those are the things we ask for. Those are the things that we are pulling live. So just think about the different powerful ways you can use this. Note, you can use this wherever lava is. So whether it's within a workflow or somewhere else, you can pull live data from all sorts of sources and use that data.
Okay. Now you can pull data from outside of Rock into Rock and use that however you want to. Just remember as a helpful tip, it's nice to add caching for these sorts of statements so that you're not reloading this API call every time your page loads, which means you could incur costs depending on the API that you're using or there could be performance impact. But thank you for watching this video, and I hope you have a great day.