Skip to content

Commit fabefc1

Browse files
Add docs from gofiber/fiber@7cddb84
1 parent 3c89cd4 commit fabefc1

File tree

1 file changed

+35
-28
lines changed

1 file changed

+35
-28
lines changed

docs/core/intro.md

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ id: welcome
44
title: 👋 Welcome
55
sidebar_position: 1
66
---
7-
An online API documentation with examples so you can start building web apps with Fiber right away!
7+
Welcome to the online API documentation for Fiber, complete with examples to help you start building web applications with Fiber right away!
88

9-
**Fiber** is an [Express](https://github.com/expressjs/express) inspired **web framework** built on top of [Fasthttp](https://github.com/valyala/fasthttp), the **fastest** HTTP engine for [Go](https://go.dev/doc/). Designed to **ease** things up for **fast** development with **zero memory allocation** and **performance** in mind.
9+
**Fiber** is an [Express](https://github.com/expressjs/express)-inspired **web framework** built on top of [Fasthttp](https://github.com/valyala/fasthttp), the **fastest** HTTP engine for [Go](https://go.dev/doc/). It is designed to facilitate rapid development with **zero memory allocations** and a strong focus on **performance**.
1010

11-
These docs are for **Fiber v3**, which was released on **March XX, 2024**.
11+
These docs are for **Fiber v3**, which was released on **Month xx, 202x**.
1212

1313
### Installation
1414

15-
First of all, [download](https://go.dev/dl/) and install Go. `1.22` or higher is required.
15+
First, [download](https://go.dev/dl/) and install Go. Version `1.22` or higher is required.
1616

1717
Installation is done using the [`go get`](https://pkg.go.dev/cmd/go/#hdr-Add_dependencies_to_current_module_and_install_them) command:
1818

@@ -22,7 +22,7 @@ go get github.com/gofiber/fiber/v3
2222

2323
### Zero Allocation
2424

25-
Fiber is optimized for **high-performance**, meaning values returned from **fiber.Ctx** are **not** immutable by default and **will** be re-used across requests. As a rule of thumb, you **must** only use context values within the handler and **must not** keep any references. Once you return from the handler, any values obtained from the context will be re-used in future requests. Here is an example:
25+
Fiber is optimized for **high performance**, meaning values returned from **fiber.Ctx** are **not** immutable by default and **will** be reused across requests. As a rule of thumb, you **must** only use context values within the handler and **must not** keep any references. Once you return from the handler, any values obtained from the context will be reused in future requests. Here is an example:
2626

2727
```go
2828
func handler(c fiber.Ctx) error {
@@ -44,13 +44,13 @@ func handler(c fiber.Ctx) error {
4444
buffer := make([]byte, len(result))
4545
copy(buffer, result)
4646
resultCopy := string(buffer)
47-
// Variable is now valid forever
47+
// Variable is now valid indefinitely
4848

4949
// ...
5050
}
5151
```
5252

53-
We created a custom `CopyString` function that does the above and is available under [gofiber/utils](https://github.com/gofiber/utils).
53+
We created a custom `CopyString` function that performs the above and is available under [gofiber/utils](https://github.com/gofiber/utils).
5454

5555
```go
5656
app.Get("/:foo", func(c fiber.Ctx) error {
@@ -61,19 +61,19 @@ app.Get("/:foo", func(c fiber.Ctx) error {
6161
})
6262
```
6363

64-
Alternatively, you can also use the `Immutable` setting. It will make all values returned from the context immutable, allowing you to persist them anywhere. Of course, this comes at the cost of performance.
64+
Alternatively, you can enable the `Immutable` setting. This makes all values returned from the context immutable, allowing you to persist them anywhere. Note that this comes at the cost of performance.
6565

6666
```go
6767
app := fiber.New(fiber.Config{
6868
Immutable: true,
6969
})
7070
```
7171

72-
For more information, please check [**\#426**](https://github.com/gofiber/fiber/issues/426), [**\#185**](https://github.com/gofiber/fiber/issues/185) and [**\#3012**](https://github.com/gofiber/fiber/issues/3012).
72+
For more information, please refer to [#426](https://github.com/gofiber/fiber/issues/426), [#185](https://github.com/gofiber/fiber/issues/185), and [#3012](https://github.com/gofiber/fiber/issues/3012).
7373

7474
### Hello, World
7575

76-
Embedded below is essentially the most straightforward **Fiber** app you can create:
76+
Below is the most straightforward **Fiber** application you can create:
7777

7878
```go
7979
package main
@@ -95,15 +95,15 @@ func main() {
9595
go run server.go
9696
```
9797

98-
Browse to `http://localhost:3000` and you should see `Hello, World!` on the page.
98+
Browse to `http://localhost:3000` and you should see `Hello, World!` displayed on the page.
9999

100-
### Basic routing
100+
### Basic Routing
101101

102-
Routing refers to determining how an application responds to a client request to a particular endpoint, which is a URI (or path) and a specific HTTP request method (`GET`, `PUT`, `POST`, etc.).
102+
Routing determines how an application responds to a client request to a particular endpoint, which is a URI (or path) and a specific HTTP request method (`GET`, `PUT`, `POST`, etc.).
103103

104104
Each route can have **multiple handler functions** that are executed when the route is matched.
105105

106-
Route definition takes the following structures:
106+
Route definitions follow the structure below:
107107

108108
```go
109109
// Function signature
@@ -115,10 +115,10 @@ app.Method(path string, ...func(fiber.Ctx) error)
115115
- `path` is a virtual path on the server
116116
- `func(fiber.Ctx) error` is a callback function containing the [Context](https://docs.gofiber.io/api/ctx) executed when the route is matched
117117

118-
#### Simple route
118+
#### Simple Route
119119

120120
```go
121-
// Respond with "Hello, World!" on root path, "/"
121+
// Respond with "Hello, World!" on root path "/"
122122
app.Get("/", func(c fiber.Ctx) error {
123123
return c.SendString("Hello, World!")
124124
})
@@ -131,21 +131,22 @@ app.Get("/", func(c fiber.Ctx) error {
131131

132132
app.Get("/:value", func(c fiber.Ctx) error {
133133
return c.SendString("value: " + c.Params("value"))
134-
// => Get request with value: hello world
134+
// => Response: "value: hello world"
135135
})
136136
```
137137

138-
#### Optional parameter
138+
#### Optional Parameter
139139

140140
```go
141141
// GET http://localhost:3000/john
142142

143143
app.Get("/:name?", func(c fiber.Ctx) error {
144144
if c.Params("name") != "" {
145145
return c.SendString("Hello " + c.Params("name"))
146-
// => Hello john
146+
// => Response: "Hello john"
147147
}
148148
return c.SendString("Where is john?")
149+
// => Response: "Where is john?"
149150
})
150151
```
151152

@@ -156,27 +157,33 @@ app.Get("/:name?", func(c fiber.Ctx) error {
156157

157158
app.Get("/api/*", func(c fiber.Ctx) error {
158159
return c.SendString("API path: " + c.Params("*"))
159-
// => API path: user/john
160+
// => Response: "API path: user/john"
160161
})
161162
```
162163

163-
### Static files
164+
### Static Files
164165

165-
To serve static files such as **images**, **CSS**, and **JavaScript** files, replace your function handler with a file or directory string.
166-
You can check out [static middleware](./middleware/static.md) for more information.
167-
Function signature:
166+
To serve static files such as **images**, **CSS**, and **JavaScript** files, use the `Static` method with a directory path. For more information, refer to the [static middleware](./middleware/static.md).
168167

169168
Use the following code to serve files in a directory named `./public`:
170169

171170
```go
172-
app := fiber.New()
171+
package main
172+
173+
import (
174+
"github.com/gofiber/fiber/v3"
175+
)
173176

174-
app.Get("/*", static.New("./public"))
177+
func main() {
178+
app := fiber.New()
175179

176-
app.Listen(":3000")
180+
app.Static("/", "./public")
181+
182+
app.Listen(":3000")
183+
}
177184
```
178185

179-
Now, you can load the files that are in the `./public` directory:
186+
Now, you can access the files in the `./public` directory via your browser:
180187

181188
```bash
182189
http://localhost:3000/hello.html

0 commit comments

Comments
 (0)