#Serverless is a trend nowadays. Somebody of my readers may miss this, so let’s explain the term.
Suppose, you need to develop a typical web application: some data to store in a relational database, CRUD controller with some business logic, REST interface given to a website or a mobile app.
The classical approach is to rent a server, install an application server(like tomcat/jetty/wildfly), pick a server side technology like Spring, Java EE, Node.js etc. Then create the same environment locally and at last, develop the app itself, checking that all your REST controllers are configured correctly, have proper connection to a database, etc. Don’t forget about security and proper scaling for your application. Plenty of stuff aside of writing the app itself, huh?
Serverless is an approach when everything (literally!) except the code is provided for you. There is still the server but it’s hosted on some platform, the data store is on the same platform and already configured to be properly accessible from your webapp, the REST controllers are ready as well.
Your concern is only write the code.
There are several platforms for serverless like Google Cloud Functions, Amazon Lambda, etc.
Today we are talking about Backendless.com: pretty obvious this is a serverless platform and I had a chance to try it recently. They provide sophisticated datastore you can create a data scheme for, the hosting for your REST services, security configuration, auto-scaling etc.
Officially Java is a supported language, but you know Kotlin is a big player here, right? Good news we can develop applications with Kotlin for Backendless.com and here is a step by step guide.
Start with downloading the Application template and choose Java.
Open the .ipr file in IntelliJ Idea(maven/gradle is not supported yet).
- Create any new Kotlin file
- When prompted with Configure Kotlin press Configure
- Move all jars from lib folder to libs as Backendless uses libs folder(you can check in runner.properties file in a bin folder)
- Create your service in Kotlin, don’t forget to implement IBackendlessService interface.
- Configure build path of your project to put classes to “classes” folder
- Configure build path of your module to put classes directly to root of “classes”
Be sure the class you return from the service is
- Having a default constructor
- Having setters/getters for each of the data field(for data classes that means the variables are var, not val)
One more nuance: you are definitely going to write unit tests. Be sure your compiled classes don’t get written to “classes” folder, that’s screwing up the CodeRunner and Deploy processes.
That’s it! Now you can run CodeRunner and test your service.