Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
October 28, 2021 09:16 am GMT

Kotlin In Appwrite

Appwrite is an end-to-end backend server that is aiming to abstract the complexity of common, complex, and repetitive tasks required for building a modern app.

Appwrite is both cross-platform and technology agnostic, meaning it can run on any operating system, coding language, framework, or platform. Although Appwrite can easily fit the definition of serverless technology, it's designed to run well in multiple configurations.
It provides various libraries for major programming languages and platforms so you don't have to write code for interacting with our HTTP APIs from scratch.

Appwrite has divided SDKs into two categories

  • Client SDKs
  • Server SDKs

Client SDKs

  • Web SDK
  • Flutter SDK
  • Apple SDK
  • Android SDK

Server SDKs

  • Kotlin SDK
  • Dart SDK
  • Swift SDK
  • Python SDK
  • Ruby SDK and etc

Here we will be seeing how to use kotlin in Appwrite functions

So what is Kotlin?

Kotlin is a cross-platform, statically typed, general-purpose programming language with type inference.

Kotlin is designed to interoperate fully with Java, and the JVM version of Kotlin's standard library depends on the Java Class Library, but type inference allows its syntax to be more concise.

So how to write kotlin in appwrite function and for this install Kotlin SDK by following the below instructions

GRADLE

  • Appwrite's Kotlin SDK is hosted on Maven Central. In order to fetch the Appwrite SDK, add this to your root-level build.gradle(.kts) file:
repositories {          mavenCentral()} 
  • Next, add the dependency to your project's build.gradle(.kts) file:implementation("io.appwrite:sdk-for-kotlin:0.1.1")

MAVEN

  • Add this to your pom.xml
    <dependency>        <groupId>io.appwrite</groupId>        <artifactId>sdk-for-kotlin</artifactId>        <version>0.1.1</version>    </dependency></dependencies>

Add the function

You can add a new function from your Appwrite project's dashboard. Access your Functions settings from your project's left navigation panel. Click the Add Function button and choose your function name and code runtime.

Init your SDK

  • Initialize your SDK with your Appwrite server API endpoint and project ID which can be found in your project settings page and your new API secret Key project API keys section.

This can be found out when you install Appwrite according to the Operating System and access the Appwrite Console UI

setting project

Make your First Request

first request

As of now, we have seen how to set up the functions and Kotlin SDK.
Now, we will be seeing different operations which can be performed on these functions.

  • List functions :To get a list of all the project's functions. You can use the query params to filter your results.
import io.appwrite.Clientimport io.appwrite.services.Functionssuspend fun main() { val client = Client(context) .setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint .setProject("5df5acd0d48c2") // Your project ID .setKey("919c2d18fb5d4...a2ae413da83346ad2") // Your secret API key val functions = Functions(client) val response = functions.list( ) val json = response.body?.string() }
  • Get function :It will get a function by its unique ID.
val response = functions.get( functionId = "[FUNCTION_ID]" )
  • Update function :It will update the function by its unique ID.
val response = functions.update( functionId = "[FUNCTION_ID]",name = "[NAME]", execute = listOf(), )
  • Delete function :It will delete a function by its unique ID.
val response = functions.delete( functionId = "[FUNCTION_ID]" ) 
  • Create execution :Trigger a function execution. The returned object will return you the current execution status. You can ping the Get Execution endpoint to get updates on the current execution status. Once this endpoint is called, your function execution process will start asynchronously.
val response = functions.createExecution( functionId = "[FUNCTION_ID]", )

So this is the basic idea of how to create functions in the Appwrite using the Kotlin SDK.
For more you can always refer to appwrite docs

Thank You


Original Link: https://dev.to/oshi36/kotlin-in-appwrite-7n2

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To