Skip to content

Commit

Permalink
chore: Housekeeping
Browse files Browse the repository at this point in the history
  • Loading branch information
dnys1 committed Oct 16, 2024
1 parent 57bf90f commit 969829f
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 34 deletions.
4 changes: 2 additions & 2 deletions pages/docs/_meta.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"index": "Overview",
"index": "What is Celest?",
"get-started": "Getting Started",
"download": "Download",
"get-started": "Get Started",
"--celest": {
"title": "Celest",
"type": "separator"
Expand Down
8 changes: 4 additions & 4 deletions pages/docs/functions/creating-functions.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Writing a cloud function
description: Learn how to write your first Celest cloud function.
title: Creating a function
description: Learn how to create your first Celest cloud function.
---

import { Callout } from 'nextra/components'
Expand All @@ -11,9 +11,9 @@ Create serverless functions with Celest to connect different parts of your backe
You define cloud functions as regular Dart functions and Celest will automatically configure the HTTP endpoints, manage the serialization
of Dart types to and from JSON and, when you're ready, deploy your functions to the cloud.

## Building Celest Functions
## Writing Celest Functions

To start building your serverless cloud function, navigate to the `my_celest_app/celest/lib/src/functions/` folder and create a file named `<api_name>.dart`. You can create as many APIs as you want in this directory.
To write your first serverless cloud function, navigate to the `my_celest_app/celest/lib/src/functions/` folder and create a file named `<api_name>.dart`. You can create as many APIs as you want in this directory.
Each file groups and organizes multiple Celest Functions of similar functionality into a namespace.

Celest Functions are defined as top-level functions as shown below.
Expand Down
41 changes: 17 additions & 24 deletions pages/docs/functions/env-variables.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,19 @@ The value of `MY_ENV` will be `local-value` when you run `celest start`, and `pr

## Using environment variables with Celest Functions

To provide a function access to an environment variable when it runs, pass it as a parameter and annotate with the variable definition.
In the following code snippet, the `MY_ENV` value is injected into the `sayHello` function by Celest at runtime.
To get the value of an environment variable in a Celest Function, you can use the generated `celest` global. Just like in your Flutter app,
Celest will generated some helper methods to access important parts of your project.

```dart {9,11} filename="celest/lib/src/functions/greeting.dart"
import 'package:http/http.dart' as http;
In this case, we can use `celest.variables.myEnv` to access the value of the `MY_ENV` environment variable.

// We import `myEnv` from our `project.dart` file
import '../project.dart';
```dart {6} filename="celest/lib/src/functions/greeting.dart"
// Import the generated `celest` global
import 'package:celest_backend/src/generated/cloud.celest.dart';
@cloud
Future<String> sayHello(
String name, {
@myEnv required String myEnvValue,
}) async {
return 'Hello, $name! My environment variable is $myEnvValue';
Future<String> sayHello(String name) async {
print('My environment variable is ${celest.variables.myEnv}');
return 'Hello, $name!';
}
```

Expand All @@ -97,22 +95,17 @@ const myEnv = env('MY_ENV');
const mySecret = secret('MY_SECRET');
```

Then, you can use the secret in your Celest Functions in the same way as environment variables.
Then, you can use the `celest.secrets` helper in your functions in the same way as environment variables.

```dart {10,13} filename="celest/lib/src/functions/greeting.dart"
import 'package:http/http.dart' as http;
// We import `myEnv` and `mySecret` from our `project.dart` file
import '../project.dart';
```dart {7} filename="celest/lib/src/functions/greeting.dart"
// Import the generated `celest` global
import 'package:celest_backend/src/generated/cloud.celest.dart';
@cloud
Future<String> sayHello(
String name, {
@myEnv required String myEnvValue,
@mySecret required String mySecretValue,
}) async {
return 'Hello, $name! My environment variable is $myEnvValue '
'and my secret is $mySecretValue';
Future<String> sayHello(String name) async {
print('My environment variable is ${celest.variables.myEnv}');
print('My secret is ${celest.secrets.mySecret}');
return 'Hello, $name!';
}
```

Expand Down
4 changes: 2 additions & 2 deletions pages/docs/get-started.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ This guide walks you through setting up Celest on your development machine, and

To get started with Celest, you'll need to configure your development environment so that you have Flutter and the Celest CLI installed on your machine.

1. Install [Flutter](https://docs.flutter.dev/get-started/install) from the official website
2. [Download](https://celest.dev/download) and install the Celest CLI
1. Install Flutter v3.24.0 or later from the [official website](https://docs.flutter.dev/get-started/install)
2. Download and install the [Celest CLI](https://celest.dev/download)

## Creating a project

Expand Down
4 changes: 2 additions & 2 deletions pages/docs/index.mdx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: Overview
title: What is Celest?
description: Learn more about Celest and how it helps you build the backend for your Flutter app.
---

Expand All @@ -24,7 +24,7 @@ Celest offers the following building blocks for your backend:
<div className="my-8">
<Cards displayName="Features">
<div className="flex flex-col">
<Card icon={<FunctionsIcon />} title="Functions" href="/docs/functions/introduction" />
<Card icon={<FunctionsIcon />} title="Functions" href="/docs/functions" />
<p className="text-sm text-gray-200 font-medium my-6 px-2 text-center">Build functions that run in the cloud with your custom business logic.</p>
</div>
<div className="flex flex-col">
Expand Down

0 comments on commit 969829f

Please sign in to comment.