Examples

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 collection with the following attributes:

NameTypeDescription
title
string
The name of the topic
description
string
Long form description of the topic

Create a Votes collection with the following attributes:

NameTypeDescription
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 collection. 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 collection with the following attributes:

NameTypeDescription
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 collection.