Introducing Request, where the information lives! So, with the App object selectd, choose Insert > Event in order to add the HandleSpecialURL event, as is shown in the following picture:Īs we will see, once the event has been added to a web app, it will receive the Request parameter (a WebRequest data type), waiting from us to send back a Boolean value as response: True to process the request or False (the default value) to ignore the response. Where getCustimers is in this case one of our API methods. In addition, this is the event that will allow our Web apps to attend and process the callbacks from other external web services, as could be PayPal, for example.įor example, a valid URL that can be trapped and processed by HandleSpecialURL is: The unique consideration is that these URL need to include the word Special or API as part of their URL path. The main difference is that, in this case, we can use typical URL signatures when its about talk with web APIs, where the methods (i.e, the requested action by the clients or API consumers) is part of the URL itself. However, for web services we need to add the HandleSpecialURLevent to our project. If we were writing a Web App, then this would be the event we would use to attend, process and send the requested web pages, for example. This is the one that fires every time a client app (it may be a Web Browser, desktop or mobile app) connects to the URL associated with the IP address and port combination that is listening for incoming requests. Xojo Web projects offer two ways to handle the request received.
If database.Error then MsgBox "Error connecting to the database"Īs you can see, it is pretty much the same code we already use when creating SQLiteDatabase instances in our Desktop apps, linking to our SQLite database file and stablishing the connection so we can operate with the database engine from our app. Write the following code in the resulting Code Editor: dim f as FolderItem = ("test.sqlite") For that, make sure the App object is selected and add the Open Event Handler to it using the Insert > Event option. Now is time to create a new SQLiteDatabase instance and assign it to this property, so it will point to the SQLite database file when the app is running. With the new property selected, go to the Inspector to set the name, type and scope using these values: Select the App object from the Navigator (the left panel in the Xojo IDE), choosing the Insert > Property option from the contextual menu. Start by adding a new property in charge of the reference to our SQLite database (of course, it will work also with PostgreSQL or MySQL engines). In fact this tutorial will put all the logic in the App object. The good part is that you can mix both worlds, adding the webservice part to your regular Web app!. The first thing you’ll notice is that Xojo adds a web page to the project by default – even when our web service does not display a UI. Let’s start creating a web service! Open the Xojo IDE, create a new Web project, and name it WebService.
In addition, if you want to follow and reproduce the steps of this tutorial, then you need to download the Chinook Database, named “test.sqlite” in this tutorial. In the second part, we will create a Desktop client to talk with the web service (you may want to add iOS to the list).īefore we start, let me point out that this tutorial leaves out some details related to error checking, validation, data sanitizing and other specifics related to inputs and outputs in order to focus on the central topic. In this two part tutorial you will see how easy it is to create a basic web service using Xojo Web. Learn about APIs and web services with Xojo in the tutorial blog post. Of course, Xojo Web not only makes it possible to create your own web apps, but it also acts as the perfect middleware that your desktop and iOS apps can communicate with. I’m looking at you: HTML, CSS (is that even a language?), JavaScript, PHP, et al. Using Xojo Web to create complete web apps and solutions means not having to learn a bunch of interpreted languages and dozens of ever-changing frameworks.