Skip to content
This repository has been archived by the owner on Sep 29, 2023. It is now read-only.

Functions G4 #398

Merged
merged 89 commits into from
Aug 27, 2023
Merged

Functions G4 #398

merged 89 commits into from
Aug 27, 2023

Conversation

gewenyu99
Copy link
Contributor

What does this PR do?

(Provide a description of what this PR does.)

Test Plan

(Write your test plan here. If you changed any code, please provide us with clear instructions on how you verified your changes work.)

Related PRs and Issues

(If this PR is related to any other PR or resolves any issue or related to any issue link all related PR and issues here.)

Have you read the Contributing Guidelines on issues?

(Write your answer here.)

Behind the simple workflow hides some useful recipes that can help you accomplish your goals faster.
Take a look at the following.
</p>
[TODO: @matej @luke -> Let's have some simple recipes here for common actions]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For example: Matej suggested these, would be a starting point:

Hmm here is an idea, let me know what you think:

Section 1: My first function

We inform we are going to build currency convertion function
Create new file, index.js
We put some very very simple code into index.js, statically returning 1.13 (because 1€ = 1.13$)
We use git to init, commit, add remote and push
We create function in Console
We exectue function and see response 1.13 (by visiting URL like ghrfu9ewji.functions.appwrite.app)

Section 2: Let's use Payload
We update code in index.js to use req.query.amount. In URL param we recieve how much money you want to convert. Let's say body is 5 (€), we would return 5.63 ($). Still only using static math ($ = € * 1.13)
Push, wait a little, refresh static domain
Play with different params and see resposne number change

Section 3: Installing dependencies
Run npm init --yes to prepare dependency file
Install HTTP client library, npm install axios
Use axios with exchange API to get the rate instead of having it static. FOr example this, it's 100% free without limits: https://cdn.jsdelivr.net/gh/fawazahmed0/currency-api@1/latest/currencies/eur/usd.json
Push, wait a little, refresh static domain
Play around and see same results, just a bit more precise

Section 4: More routes
Edit index.js to support multipel paths like /eur, /czk, /ft, /rub...
Push, deploy..
Try different endpoints, see they all convert that currency into $


Aaaand we can make this very generic, and have code and command snippets switchable between all runtimes

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done for js

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done for php dart ruby python

</div>

<h3>Manual Deployment</h3>
<p>You can also upload your functions to be deployed using the Appwrite console. The example below shows a simple Node.JS function, but the same idea applies to any other language.</p>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<p>You can also upload your functions to be deployed using the Appwrite console. The example below shows a simple Node.JS function, but the same idea applies to any other language.</p>
<p>You can upload your functions to be deployed using the Appwrite Console. The example below shows a simple Node.js function, but the same idea applies to any other language.</p>

</li>
</ul>

<p>Next, navigate to your Appwrite console and upload the function.</p>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<p>Next, navigate to your Appwrite console and upload the function.</p>
<p>Next, navigate to your Appwrite Console and upload the function.</p>

<li class="margin-bottom-small">Click <b>Create</b> to deploy your function.</li>
</ol>

<h2><a href="#domains" id="domains">Domains</a></h2>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm a bit concerned here. Should this be in deploy, or execute section? 🤔
On one hand, it makes sense here as someone deploying their function to production needs this information.
On the other hand, we talk about how to execute using domain in execute page. So it might make sense there as well.

Your call, just wanted to bring in the chaos 😈

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both

<ol class="margin-top margin-bottom-large text-size-normal">
<li class="margin-bottom-small">Navigate to the Appwrite Console's <b>Functions</b> page.</li>
<li class="margin-bottom-small">Navigate to the <b>Domains</b> tab.</li>
<li class="margin-bottom-small">In the table, you'll find a link formatted similar to <code>https://64d4d22db370ae41a32e.appwrite.global</code>. This is your preview.</li>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets not call it "preview". THat insicates it cant be used for production, but it can.

<li>In Appwrite Console, navigate to <b>Functions</b>.</li>
<li>Click to open a function you wish to inspect.</li>
<li>Under the <b>Deployments</b> tab, you'll find the status of the current active deployment.</li>
<li>You can redeploy by clicking the <b>Redeploy</b> button.</li>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets mention that you can redeploy failed execution by clicking 3 dots and finding same Redeploy button

Here's everything you need to know to deploy your first Appwrite Function.
</p>

<h2><a href="#vcs" id="vcs">VCS (Version Control System)</a></h2>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not entirely onboard with calling it VCS in docs. I think calling it Git, and mentioning GitHub would feel more natural to developer. You can double check with Eldad.

@gewenyu99 gewenyu99 marked this pull request as ready for review August 27, 2023 15:12
@gewenyu99 gewenyu99 merged commit 991c312 into 1.4.x Aug 27, 2023
@gewenyu99 gewenyu99 deleted the functions-g4 branch September 3, 2023 15:09
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants