This content originally appeared on DEV Community and was authored by Oshi Gupta
In the previous blog we have seen about how to use Kotlin in Appwrite. Now we will be seeing about how to use Dart in Appwrite.
As we Dart SDK is one of the server SDKs in Appwrite but first let's know what is Dart?
Dart is an open-source, general-purpose, object-oriented programming language with C-style syntax developed by Google in 2011. The purpose of Dart programming is to create a frontend user interfaces for the web and mobile apps.
So now how to write Dart in Appwrite function and how to install Dart SDK for it.
Dart SDK Installation
- Add this to your package's pubspec.yaml file:
dependencies:
dart_appwrite: ^1.0.2
- You can install packages from the command line:
pub get dart_appwrite
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
Make your first request
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 'package:dart_appwrite/dart_appwrite.dart';
void main() { // Init SDK
Client client = Client();
Functions functions = Functions(client);
client
.setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
.setProject('5df5acd0d48c2') // Your project ID
.setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
;
Future result = functions.list(
);
result
.then((response) {
print(response);
}).catchError((error) {
print(error.response);
});
}
- Get function : It will get a function by its unique ID.
import 'package:dart_appwrite/dart_appwrite.dart';
void main() { // Init SDK
Client client = Client();
Functions functions = Functions(client);
client
.setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
.setProject('5df5acd0d48c2') // Your project ID
.setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
;
Future result = functions.get(
functionId: '[FUNCTION_ID]',
);
result
.then((response) {
print(response);
}).catchError((error) {
print(error.response);
});
}
- Update function : It will update the function by its unique ID.
import 'package:dart_appwrite/dart_appwrite.dart';
void main() { // Init SDK
Client client = Client();
Functions functions = Functions(client);
client
.setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
.setProject('5df5acd0d48c2') // Your project ID
.setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
;
Future result = functions.update(
functionId: '[FUNCTION_ID]',
name: '[NAME]',
execute: [],
);
result
.then((response) {
print(response);
}).catchError((error) {
print(error.response);
});
}
So this is the basic idea of how to create functions in the Appwrite using the Dart SDK.
For more you can always refer to Appwrite docs
Thank You
This content originally appeared on DEV Community and was authored by Oshi Gupta
Oshi Gupta | Sciencx (2021-10-31T17:16:56+00:00) Dart In Appwrite. Retrieved from https://www.scien.cx/2021/10/31/dart-in-appwrite/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.