mirror of
https://github.com/LukeHagar/website.git
synced 2025-12-09 04:22:13 +00:00
First draft of refactored function docs
This commit is contained in:
@@ -44,16 +44,16 @@
|
||||
label: 'Runtimes',
|
||||
href: '/docs/products/functions/runtimes'
|
||||
},
|
||||
{
|
||||
label: 'Templates',
|
||||
href: '/docs/products/functions/templates'
|
||||
},
|
||||
|
||||
]
|
||||
},
|
||||
{
|
||||
label: 'Journeys',
|
||||
items: [
|
||||
{
|
||||
label: 'Templates',
|
||||
href: '/docs/products/functions/templates'
|
||||
},
|
||||
{
|
||||
label: 'Develop',
|
||||
href: '/docs/products/functions/develop'
|
||||
|
||||
@@ -1089,7 +1089,6 @@ You can access these logs through the following steps.
|
||||
|
||||
# Accessing environment variables {% #environment-variables %}
|
||||
If you need to pass constants or secrets to Appwrite Functions, you can use environment variables.
|
||||
Environmental variables can be global, or function-specific.
|
||||
|
||||
{% info title="Appwrite API keys" %}
|
||||
If your function is using an Appwrite SDK with an API key, this API key needs to be generated and passed in manually. API keys are not passed by default for security reasons.
|
||||
@@ -1104,22 +1103,9 @@ If your function is using an Appwrite SDK with an API key, this API key needs to
|
||||
| `APPWRITE_FUNCTION_RUNTIME_NAME` | The runtime of the running function. |
|
||||
| `APPWRITE_FUNCTION_RUNTIME_VERSION` | The runtime version of the running function. |
|
||||
|
||||
## Function-level environment variables {% #function-variables %}
|
||||
Function-level environment variables will only be accessible in the function they belong to.
|
||||
Function-level environment variables will override project-level variables when they have conflicting names.
|
||||
|
||||
1. In Appwrite Console, navigate to **Functions**.
|
||||
2. Click to open a function you wish to add variables to.
|
||||
3. Under the **Settings** tab, navigate to **Environment variables**.
|
||||
4. Create an environment variable by clicking **Create variable**, using the **Editor**, or import new variables through a `.env` file.
|
||||
|
||||
## Project-level variables {% #project-variables %}
|
||||
Project-level variables are accessible to all Appwrite Functions in your project.
|
||||
Function-level environment variables will override project-level variables when they have conflicting names.
|
||||
|
||||
In the Appwrite Console, navigate to your project's **Settings** page.
|
||||
Navigate to **Global variables** section.
|
||||
Create an environment variable by clicking **Create variable**, using the **Editor**, or import new variables through a `.env` file.
|
||||
{% arrow_link href="/docs/products/functions/functions" %}
|
||||
Learn to add variables to you function
|
||||
{% /arrow_link %}
|
||||
|
||||
You can access the environment variables through the systems library of each language.
|
||||
|
||||
@@ -2184,21 +2170,4 @@ public class Main {
|
||||
}
|
||||
```
|
||||
{% /tabsitem %}
|
||||
{% /tabs %}
|
||||
|
||||
# Upgrade {% #upgrade %}
|
||||
|
||||
Appwrite Functions received major updates in Appwrite version 1.4.
|
||||
Your old function from 1.3 will continue to work, but it can't be updated directly to a 1.4 function.
|
||||
You need to create a new function following 1.4 syntax.
|
||||
After you've created your new function, point your application code to the new function and delete the old function.
|
||||
|
||||
Here's a checklist of things you need to know.
|
||||
|
||||
1. The parameter passed into functions has changed. `req` and `res` has been replaced by `context`, which contains new logger methods. [Learn about context](/docs/products/functions/development#context-object).
|
||||
2. To improve privacy and logging reliability, we provide new `context.log()` and `context.error()` functions. You can no longer use native logging methods. [Learn about logging](/docs/products/functions/development#logging).
|
||||
3. The old way of `req.variables` has been deprecated. You can now access variables passed into each function as environment variables. [Learn about environment variables](/docs/products/functions/development#environment-variables).
|
||||
4. The `req` object has been updated to use terminology consistent with typical HTTP concepts. You'll now find familiar concepts like headers, body, HTTP methods, and others. [Learn about request](/docs/products/functions/development#request).
|
||||
5. The response object has been updated. You can now specify headers, as well as use new methods like return redirects or empty responses. [Learn about response](/docs/products/functions/development#response).
|
||||
6. Now, you must return a response such as return `context.res.send("")`. This prevents confusing errors when functions are terminated prematurely before a response is sent. [Learn about response](/docs/products/functions/development#response).
|
||||
7. Some variables about how a function was triggered are now found in the context.req object as headers.
|
||||
{% /tabs %}
|
||||
@@ -490,14 +490,6 @@ Here are some cron expressions for common intervals:
|
||||
|
||||
# Permissions {% #permission %}
|
||||
|
||||
|
||||
Appwrite Functions can be executed using Client or Server SDKs. Client SDKs must be authenticated with an account that has been granted execution [permissions](/docs/advanced/platform/permissions) on the function's settings page. Server SDKs require an API key with the correct scopes.
|
||||
|
||||
If your function has a generated or custom domain, executions are not authenticated. Anyone visiting the configured domains will be considered a guest, so make sure to give `Any` execute permission in order for domain executions to work. If you need to enforce permissions for functions with a domain, use authentication methods like JWT.
|
||||
|
||||
|
||||
# Logs and results {% #logs %}
|
||||
|
||||
You can view the logs of your function executions in the Appwrite Console. Navigate to **Functions** and click on a function to view its executions.
|
||||
|
||||
For security reasons, Appwrite does not store the response of function executions. If you need to debug, we recommend logging the response in your function code.
|
||||
If your function has a generated or custom domain, executions are not authenticated. Anyone visiting the configured domains will be considered a guest, so make sure to give `Any` execute permission in order for domain executions to work. If you need to enforce permissions for functions with a domain, use authentication methods like JWT.
|
||||
@@ -58,10 +58,10 @@ Each execution can have one of the follow status.
|
||||
When you click on an execution, you will be taken to an execution detail screen.
|
||||
|
||||
{% only_dark %}
|
||||

|
||||

|
||||
{% /only_dark %}
|
||||
{% only_light %}
|
||||

|
||||

|
||||
{% /only_light %}
|
||||
|
||||
You can find both request and response details.
|
||||
|
||||
@@ -172,6 +172,8 @@ Here are some cron expressions for common intervals:
|
||||
Set static environment variables that will be passed to your function
|
||||
by navigating to your function > **Settings** > **Environment variables**.
|
||||
|
||||
You can also configure global variables that apply to all your functions in the **Settings** of your project.
|
||||
|
||||
{% info title="Redeployment required" %}
|
||||
This change requires your function to be redeployed to take effect.
|
||||
{% /info %}
|
||||
|
||||
128
src/routes/docs/products/functions/templates/+page.markdoc
Normal file
128
src/routes/docs/products/functions/templates/+page.markdoc
Normal file
@@ -0,0 +1,128 @@
|
||||
---
|
||||
layout: article
|
||||
title: Templates
|
||||
description: Learn about Appwrite Functions' templates that let you jump start function development to extend your Appwrite APIs.
|
||||
---
|
||||
Appwrite provides a variety of Function Templates to help you jump start your function development.
|
||||
You can use Appwrite Function Templates as examples or boilerplates to add new functionality to your Appwrite project.
|
||||
|
||||
# Find templates {% #find-templates %}
|
||||
You can find all available templates by navigating to the Appwrite Console, under your project > **Functions** > **Templates**.
|
||||
|
||||
{% only_dark %}
|
||||

|
||||
{% /only_dark %}
|
||||
{% only_light %}
|
||||

|
||||
{% /only_light %}
|
||||
|
||||
You can filter functions by searching, filter by use case, or filter by runtime.
|
||||
Click **Create function** to create a function from a template.
|
||||
|
||||
# Create with templates {% #create-with-templates %}
|
||||
|
||||
The create function wizard has five steps.
|
||||
|
||||
## Configuration {% #configuration %}
|
||||
Pick a display name for your function and an ID. You will later use the ID to programmatically execute or configure the function.
|
||||
Pick the runtime language you wish the function to be created in, not all runtimes are available for all templates.
|
||||
|
||||
## Variables {% #variables %}
|
||||
Appwrite Functions uses [environment variables](/docs/products/functions/develop#environment-variables)
|
||||
to pass constants and secrets to your Appwrite Functions. You'll provide information like API keys and other
|
||||
secrets to integrations in this step. If you need an Appwrite API key, you'll be propted to generate one.
|
||||
|
||||
## Connect {% #connect %}
|
||||
You can choose to clone a new repository to your GitHub profile or organization, or to connect to an existing repository.
|
||||
|
||||
If you choose connect to an existing repository, the function's code will be cloned to the root folder
|
||||
you specify under the **Branch** step.
|
||||
|
||||
## Repository {% #repository %}
|
||||
Configure the connected respository for your Appwrite Function. This will be the repository
|
||||
holding the source code for your function. When the code in this repository is updated, new
|
||||
deployments will be created.
|
||||
|
||||
## Branch {% #branch %}
|
||||
Production branch specifies the branch connected to your Appwrite Function. When new commits are made to
|
||||
this branch, a new deployment is automatically created and deployed.
|
||||
|
||||
The root directory specifies the folder holding your function template's code.
|
||||
|
||||
When a PR is made to the branch, a new deployment is built, but not activated.
|
||||
A comment is made to your PR about the build, unless you enable **Silent mode**.
|
||||
|
||||
# Available templates {% #available-templates %}
|
||||
{% table %}
|
||||
* Template {% width=100 %}
|
||||
* Description
|
||||
* Runtimes {% width=200 %}
|
||||
---
|
||||
* Starter
|
||||
* A simple starter function that returns "Hello, world!"
|
||||
* Node.js, Python, PHP, Dart, Node.js (TypeScript), Bun, Deno, Ruby, Kotlin, C++, .NET, Java, Swift
|
||||
---
|
||||
* Sync with Meilisearch
|
||||
* Syncs documents in an Appwrite database collection to a Meilisearch index to add search-as-you-type search boxes to your app.
|
||||
* Node.js, Python, PHP, Node.js (TypeScript), Bun, Deno, Ruby, Kotlin
|
||||
---
|
||||
* WhatsApp with Vonage
|
||||
* Simple bot to answer WhatsApp messages.
|
||||
* Node.js, Python, PHP, Dart, Node.js (TypeScript), Bun, Deno, Ruby
|
||||
---
|
||||
* Prompt ChatGPT
|
||||
* Ask question, and let OpenAI GPT-3.5-turbo answer.
|
||||
* Node.js, Python, PHP, Dart
|
||||
---
|
||||
* Censor with Redact
|
||||
* Automatically remove sensitive data from messages.
|
||||
* Node.js, Python, Dart
|
||||
---
|
||||
* Email Contact Form
|
||||
* Sends an email with the contents of a HTML form.
|
||||
* Node.js, Python, PHP
|
||||
---
|
||||
* Sync with Algolia
|
||||
* Intuitive search bar for any data in Appwrite Databases.
|
||||
* Node.js, Python, PHP
|
||||
---
|
||||
* Discord Command Bot
|
||||
* Add Discord commands to your servers using Discord Interactions.
|
||||
* Node.js, Python
|
||||
---
|
||||
* Github Issue Bot
|
||||
* Automate the process of responding to newly opened issues on a GitHub repository.
|
||||
* Node.js, Node.js (TypeScript)
|
||||
---
|
||||
* Analyze with PerspectiveAPI
|
||||
* Automate moderation by using AI to measure the toxicity of messages.
|
||||
* Node.js
|
||||
---
|
||||
* Generate PDF
|
||||
* Generate PDFs programmatically with Appwrite Functions.
|
||||
* Node.js
|
||||
---
|
||||
* Payments with Stripe
|
||||
* Receive card payments and store paid orders.
|
||||
* Node.js
|
||||
---
|
||||
* Push Notification with FCM
|
||||
* Send push notifications to your users using Firebase Cloud Messaging (FCM).
|
||||
* Node.js
|
||||
---
|
||||
* Slack Command Bot
|
||||
* Simple command bot using Slack API
|
||||
* Node.js
|
||||
---
|
||||
* Storage Cleaner
|
||||
* Storage cleaner function to remove all files older than X number of days from the specified bucket.
|
||||
* Node.js
|
||||
---
|
||||
* Subscriptions with Stripe
|
||||
* Receive recurring card payments and grant subscribers extra permissions.
|
||||
* Node.js
|
||||
---
|
||||
* URL Shortener
|
||||
* Generate URL with short ID and redirect to the original URL when visited.
|
||||
* Node.js
|
||||
{% /table %}
|
||||
BIN
static/images/docs/functions/templates/dark/templates.png
Normal file
BIN
static/images/docs/functions/templates/dark/templates.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 251 KiB |
BIN
static/images/docs/functions/templates/templates.png
Normal file
BIN
static/images/docs/functions/templates/templates.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 222 KiB |
Reference in New Issue
Block a user