You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/intro.md
+17-77Lines changed: 17 additions & 77 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ sidebar_position: 1
4
4
5
5
# Tutorial Intro
6
6
7
-
Let's discover **Yelix in less than 5 minutes**.
7
+
Let's discover **Yelix in less than 1 minutes**.
8
8
9
9
## Getting Started
10
10
@@ -16,98 +16,38 @@ Get started by **creating a new server**.
16
16
17
17
## Generate a new server
18
18
19
-
To generate a new server, we should init before.
19
+
To generate a new server, run the following command:
20
20
21
21
```bash
22
-
deno init my-app
22
+
deno run --allow-write --allow-read https://yelix-docs.deno.dev/yelix-template.ts
23
23
```
24
24
25
-
You can type this command into Command Prompt, Powershell, Terminal, or any other integrated terminal of your code editor.
25
+
This command will create a new Yelix project with the following structure:
26
26
27
-
Move into the newly created directory:
28
-
29
-
```bash
30
-
cd my-app
31
-
```
32
-
33
-
### Install Yelix
34
-
35
-
To install Yelix, run the following command:
36
-
37
-
```bash
38
-
deno add jsr:@murat/yelix
39
27
```
40
-
41
-
This command installs the Yelix package into your project.
42
-
43
-
### Update your main file
44
-
45
-
Open the `main.ts` file in your project and add the following code:
46
-
47
-
`./main.ts`
48
-
```typescript
49
-
import { Yelix } from"jsr:@murat/yelix";
50
-
import*aspathfrom"jsr:@std/path@1.0.8";
51
-
52
-
asyncfunction main() {
53
-
// Port is 3030 by default
54
-
const app =newYelix();
55
-
56
-
// Load endpoints from a 'api' folder
57
-
const currentDir =Deno.cwd();
58
-
const API_Folder =path.join(currentDir, 'api');
59
-
awaitapp.loadEndpointsFromFolder(API_Folder);
60
-
61
-
app.serve();
62
-
}
63
-
64
-
awaitmain();
28
+
api/
29
+
└── hello.ts
30
+
deno.json
31
+
main.ts
65
32
```
66
33
67
-
This code imports the Yelix package and creates a new server instance. It then loads endpoints from a folder and serves the application.
68
-
69
-
:::caution
70
-
71
-
Deno Deploy doesn't support `loadEndpointsFromFolder` method, if you want to deploy your app on Deno Deploy, you should use `loadEndpoints` method.
72
-
73
-
Deno Deploy doesn't access dynamic importing because of security reasons.
74
-
75
-
:::
76
-
77
-
### Create an API folder
34
+
### Generated Files
78
35
79
-
Create a new folder named `api` in your project directory. Inside this folder, create a new file named `hello.ts` with the following content:
36
+
| File | Purpose | Description |
37
+
|------|---------|-------------|
38
+
|`deno.json`| Project Configuration | Contains development tasks and project settings. Defines the `dev` command used to run the server. |
39
+
|`main.ts`| Server Setup | Entry point of the application. Initializes Yelix server and configures endpoint loading from the `api` folder. |
40
+
|`api/hello.ts`| Example Endpoint | Demonstrates a basic API endpoint that returns "Hello World!" when accessed at `/api/hello`. Shows the standard endpoint structure. |
80
41
81
-
`./api/hello.ts`
82
-
```typescript
83
-
importtype { Ctx } from"jsr:@murat/yelix";
84
-
85
-
// API endpoint handler
86
-
exportasyncfunction GET(ctx:Ctx) {
87
-
returnawaitctx.text('Hello World!', 200);
88
-
}
89
-
90
-
// API endpoint configs
91
-
exportconst path ='/api/hello';
92
-
```
93
-
94
-
- Method: `GET` - Taken from the function name
95
-
- Path: `/api/hello` - Defined in the `path` variable
96
-
- Response: `Hello World!` - Returned by the `GET` function
97
-
98
-
## Start your site
42
+
### Start your server
99
43
100
44
Run the development server:
101
45
102
46
```bash
103
-
deno run --watch --allow-net --allow-read --allow-env main.ts
47
+
deno task dev
104
48
```
105
49
106
-
-`--watch` - Automatically reloads the server when changes are made
107
-
-`--allow-net` - Allows network access for serving the server
108
-
-`--allow-read` - Allows file read access for loading endpoints
109
-
-`--allow-env` - Checking where is deployed for Deno Deploy
110
-
50
+
This command will start your server in development mode with all required permissions.
0 commit comments