Working with REST services
Hi, my name is I’m going to connect to my Google Calendar using the RESTful web service. It takes a few seconds because you can see 1963 events loaded. So now here they are and I can do things like filter on them. Let’s say 2009 and maybe demo. So demos I did before 2009 from my Google Calendar or maybe I want to filter and just show only events that were canceled. So that’s a quick demo of what we’re going to learn about. Maybe I switch over a bit and give you some background info before we dive under the hood. I think there we go. Just a reminder, this is a five-part webinar series. We’re doing all this week. Today’s Wednesday, right in the middle, dynamic data sources. Tomorrow we have validation and Friday all about form components. So if you’d like this, be sure to attend Thursday and Friday. And if you missed part one and two, be sure to check out the recordings that are posted to the website. So what we’re going to do is sort of review in-memory data sources, which has been a feature in Servoy. We’re going to explore this new feature of design time data sources and then we’ll take a look at that demo that I just watched. And be kind of the hood and see how it works. Like all the other webinars, we’re laser focused on just this one features. So we should be about 20 minutes or so and time for questions and answer. So just to review in-memory data sources, it’s been supported for several years now in Servoy, I believe. And this is a handy tool to convert arbitrary data structures to the popular SQL data source that’s supported by Servoy. So things like REST, SOAP, ETL, custom queries, etc. And then once you have converted these arbitrary data sources into something structured, you can connect forms to them. And you can code against them via the found set API, etc. But there were some drawbacks, as Yawn was mentioning. There’s no static typing. The access to these data sources is programmatic only, so you have to programmatically build forms and connect things. And it’s really quite, there’s no type of checking in the IDE, etc. So this new feature, in 8.1, aims to make all of that much better. So what you can do is define a data source at design time. And then you can leverage all of the great business objects that you might be used to in Servoy. And then once you populate your data source at runtime, everything works as if you had a regular database table that you’re connecting to. So with that explanation, let’s jump in back into the demo and take a look under the hood. I’m going to bring up the data sources node in the IDE. You’ll notice right away that there’s a category here called in memory. And if you expand that, you can see data sources that you’ve defined to be in memory. So if you want to create a new in-memory data source, all you do is do something like that. And away you go, you start editing in the table editor. I’m going to cancel that one and show you the one that I’ve already pre-created. So this is the calendar events. And I didn’t pick all of the features from a Google Calendar event. But what I’ve done here is just captured a few of the key ones like when an event starts, when it ends, what the status is, and what the description is of the event. So I really just went in here and defined the data type just the same way you would do if you were creating tables through Servoy, data type, the length, etc. You can up-says. You’ll also notice that all of the other features are supported like calculations, entity methods, aggregates, events, audit, etc. So that’s really a great start. You’ll also notice that the runtime API for the data sorts itself is also supported. So we can do things like create custom queries. We can get the metadata, column names, and the table information. We can get a factory found set, etc. If we take a look at the form that was showing that list of events, it was called event list. And this is really, I think, the productive part because before this feature, if I wanted to do this, I could still do it, but I have to programmatically build the form of the solution model. So it’s very cumbersome and error prone and difficult to maintain. So now what I’ve done is I’ve created a form and you can see that I set the data source. There’s an extra node here in memory calendar event. So it’s just like I’m building a form against a regular database table. If I bring up the place field wizard, you’ll see that I get all of the columns that I define in my data source. I also define some calculations for the duration and a way to just display the duration. So I could add those as well. You’ll see at the end, the last year I have the displayed duration calculation. And if I jump into that, I just defined, you know, I subtracted the start and the end. And then I sort of parsed out how many hours and minutes there were. So that’s not a column that exists coming from the web service, but I’m adding that at the application to here. So you really get that mashup effect that you might need in a business application. Also, you’ll notice that the form had some searching and some filtering going on. So again, I can create a found set against an in memory data source. It works just like all the other data bounds forms and found set that you’re probably used to working with. So you’ll notice on the search, I was able to search for some text and all I did was put the found set into fly mode. And I’m searching for string fragment on the event summary. You’ll also notice that I was doing a bit of filtering. If I jump into the filter method, same thing. I’m working with the found set. So I’m just calling my found set add, found set filter program. And I’m able to work with the found set at runtime. Another thing that’s pretty cool is that you can actually create relations between design time data sources and other data sources. So they could be other design time data sources or tables that you have. So another use case that I’ve seen is where you actually mash up your regular database data sources. And then maybe you’re fetching something from an SAP system or somewhere else. And you have actual corresponding keys and you want to link records. As a bit difficult to come up with that in a demo. So what I did do is I created a relation here, which is a global relation essentially. It’s just a filter on the calendar events where the event status is equal to canceled. But let’s say I had a CRM and I wanted to show maybe all of the events having to do with a certain company. Then I could just build a relation, you know, company to calendar events and join on some property there. On the form here, when I was toggling the to show the relation for canceled events. Really what I’m doing is I’m just taking this form was taking control of that found set for that global relation. So all of the features that you’re used to are available on these design time data sources and it makes, makes dealing with arbitrary data structures really productive. And you get all of the features of the IDE as well, like type checking. So if I and also code complete, you’ll notice that in this form I get code complete on, you know, all of the column names. When I wanted to use the relation, I got code complete on the relation name, the calculation, etc. So and if I were to refer to something that doesn’t exist in the in the data source, I’ll also get the build markers. So I really really am adding strong typing to to my application. So that’s that’s pretty much it it’s a it’s a door demo because the the concept is fairly simple, but in lots of interactions with customers I’ve seen. I’ve seen, you know, people struggle with how to deal with arbitrary data sources, every business application has them. And I think this this feature really makes it a lot more productive. For those of you that are curious on how I was able to fetch the the events from Google calendar, it’s a bit of a off topic. But you’ll notice that when I click the button in I think it’s called event loader my form here. I’m doing some things like removing the tab and and hiding the product are showing the progress bar. And then here’s where the magic happens where I actually create the data source. The way you do it is is the same as you always have done it for in memory data sources. So first I want to say what the columns are what the data types are. Then I create a J as data set was just an in memory in memory data set to dimensional array kind of and then I call to create data source method on on the data set object now that’s that been in Servoy for quite some time and it creates that memory data source, but now it matches up to the design time data source that I’ve created. So so now when I bring up that form based on on that data source everything is available. And so what I’m doing here is is I’m getting the events from my web service and iterating over them and I’m just adding rows to the to the data set and that actually pushes them into that in memory table that I can do all the stuff against the actual fetching of the of the calendar events is kind of straightforward because it’s just rest. And so a Servoy supports HTTP connections pretty effectively. However, I have an off module because it’s a little more complicated because there’s no off on most of the those kinds of APIs. So I used an off module to get around some authentication stuff and then I really just go out and and call it get request on. Once I’ve I’ve authenticated on my Google calendar and I get back the. The response is a string and I just parse it as a JSON object and there’s really quite a bit more information there in a calendar, but I’ve chosen only to to parse out a few of the fields.