Examples_
Accelerate your serverless development with Appwrite Functions examples. Access a library of code samples and use cases to jumpstart your projects.
4 min read
Appwrite Functions is all about flexibility. Behind the simple workflow hides some useful examples that can help you accomplish your goals faster. Take a look at the following.
1. Currency conversion API
Here's a currency conversion API that converts from Euros and Indian Rupees to US Dollars. We'll use an external API to get the latest exchange rates and query it using a dependency specific to each runtime.
Prerequisites
Code
2. Voting system
Here's a simple voting system that allows users to vote on various topics. Appwrite Functions and the server SDK are used to enforce voting rules and prevent multiple votes from the same user for a single topic.
Prerequisites
Create a Topics table with the following columns:
| Name | Type | Description |
|---|---|---|
title | string | The name of the topic |
description | string | Long form description of the topic |
Create a Votes table with the following columns:
| Name | Type | Description |
|---|---|---|
userId | string | The ID of the user who cast the vote |
topicId | string | The ID of the topic that was voted on |
vote | string | The vote cast by the user. Must be either "yes" or "no" |
Code
Use the function by navigating to the function URL in the browser. The URL should contain the required parameters. For example, <YOUR_FUNCTION_URL>/?userId=<USER_ID>&topicId=<TOPIC_ID>&vote=yes to cast a vote.
3. HTML contact form
Here's a simple form page that handles form submissions, and can be used to store a user's message in a table. The form is submitted to the function using the POST method and the form data is sent as a URL-encoded string in the request body.
Prerequisites
Create a Messages table with the following columns:
| Name | Type | Description |
|---|---|---|
name | string | The name of the message author |
email | string | The email of the message author |
content | string | The content of the message |
Code
Use the function by navigating to the function URL in the browser. Submit the form to store the message in the table.
Was this page helpful?
Share what worked or what we should fix. Once approved, our agents automatically apply suggested updates to the docs.