1
0
mirror of https://github.com/gofiber/fiber.git synced 2025-02-22 22:43:54 +00:00

Update README.md

This commit is contained in:
Vic Shóstak 2020-02-01 17:32:48 +03:00 committed by GitHub
parent ec1ba416bf
commit 578f4a793c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,113 +1,146 @@
<p align="center">
<img height="150" src="https://gofiber.github.io/fiber/static/logo.jpg">
</p>
<!--
![](https://img.shields.io/github/issues/gofiber/fiber)
![](https://img.shields.io/github/stars/gofiber/fiber)
-->
# Fiber Web Framework <img src="images/flags/en.svg" alt="en"/> <a href="README_RU.md"><img src="images/flags/ru.svg" alt="ru"/></a>
# Fiber [![](https://img.shields.io/github/release/gofiber/fiber)](https://github.com/gofiber/fiber/releases) ![](https://img.shields.io/github/languages/top/gofiber/fiber) [![](https://godoc.org/github.com/gofiber/fiber?status.svg)](https://godoc.org/github.com/gofiber/fiber) ![](https://goreportcard.com/badge/github.com/gofiber/fiber)
[![](https://img.shields.io/github/release/gofiber/fiber)](https://github.com/gofiber/fiber/releases) ![](https://img.shields.io/github/languages/top/gofiber/fiber) [![](https://godoc.org/github.com/gofiber/fiber?status.svg)](https://godoc.org/github.com/gofiber/fiber) ![](https://goreportcard.com/badge/github.com/gofiber/fiber)
**[Fiber](https://github.com/gofiber/fiber)** is an **[Express](https://expressjs.com/en/4x/api.html)** styled HTTP framework implementation running on **[Fasthttp](https://github.com/valyala/fasthttp)**, the **fastest** HTTP engine for **[Go](https://golang.org/doc/)**. The package make use of similar framework convention as they are in express. People switching from **[Node](https://nodejs.org/en/about/)** to **[Go](https://golang.org/doc/)** often end up in a bad learning curve to start building their webapps, this project is meant to **ease** things up for **fast** development, but with **zero memory allocation** and **performance** in mind. See **[API Documentation](https://gofiber.github.io/fiber/)**
<img align="right" height="180px" src="https://gofiber.github.io/fiber/static/logo.jpg" />
**[Fiber](https://github.com/gofiber/fiber)** is an [Express](https://expressjs.com/en/4x/api.html)-styled HTTP web framework implementation running on [Fasthttp](https://github.com/valyala/fasthttp), the **fastest** HTTP engine for Go (Golang). The package make use of similar framework convention as they are in Express.
People switching from [Node.js](https://nodejs.org/en/about/) to [Go](https://golang.org/doc/) often end up in a bad learning curve to start building their webapps, this project is meant to **ease** things up for **fast** development, but with **zero memory allocation** and **performance** in mind.
📚 See **[API Documentation](https://gofiber.github.io/fiber/)**.
[![](https://gofiber.github.io/fiber/static/benchmarks/benchmark.png)](https://gofiber.github.io/fiber/#/benchmarks)
**[Click here to see all benchmark results](https://gofiber.github.io/fiber/#/benchmarks)**
👉 **[Click here](https://gofiber.github.io/fiber/#/benchmarks)** to see all benchmark results.
## Features
* Optimized for speed and low memory usage.
* Optimized for speed and low memory usage
* Rapid Server-Side Programming
* Easy routing with parameters
* Static files with custom prefix
* Middleware with Next support
* Express API endpoints
* **[API Documentation](https://gofiber.github.io/fiber/)**
* [Comprehensible documentation](https://gofiber.github.io/fiber/)
## Installing
Assuming youve already installed **[Go](https://golang.org/doc/)**, install the **[Fiber](https://github.com/gofiber/fiber)** package by calling the following command:
```bash
Assuming youve already installed Go `1.11+` 😉
Install the [Fiber](https://github.com/gofiber/fiber) package by calling the following command:
```console
$ go get -u github.com/gofiber/fiber
```
## Hello world
## Hello, world!
Embedded below is essentially the simplest Fiber app you can create.
```bash
$ create server.go
```
```go
// server.go
package main
import "github.com/gofiber/fiber"
func main() {
// Create new Fiber instance
app := fiber.New()
// Create new route with GET method
app.Get("/", func(c *fiber.Ctx) {
c.Send("Hello, World!")
})
// Start server on http://localhost:8080
app.Listen(8080)
}
```
```bash
Go to console and run:
```console
$ go run server.go
```
Browse to **http://localhost:8080** and you should see `Hello, World!` on the page.
And now, browse to **http://localhost:8080** and you should see `Hello, World!` on the page! 🎉
## Static files
To serve static files, use the [Static](https://gofiber.github.io/fiber/#/?id=static-files) method.
```go
package main
import "github.com/gofiber/fiber"
func main() {
// Create new Fiber instance
app := fiber.New()
// Serve all static files on ./public folder
app.Static("./public")
// Start server on http://localhost:8080
app.Listen(8080)
}
```
Now, you can load the files that are in the public directory:
```shell
```console
http://localhost:8080/hello.html
http://localhost:8080/js/jquery.js
http://localhost:8080/js/script.js
http://localhost:8080/css/style.css
```
## Middleware
Middleware has never been so easy, just like express you call the Next() matching route function!
Middleware has never been so easy, just like Express you call the `Next()` matching route function!
```go
package main
import "github.com/gofiber/fiber"
func main() {
// Create new Fiber instance
app := fiber.New()
// Define all used middlewares in Use()
app.Use(func(c *fiber.Ctx) {
c.Write("Match anything!\n")
c.Next()
})
app.Use("/api", func(c *fiber.Ctx) {
c.Write("Match starting with /api\n")
c.Next()
})
app.Get("/api/user", func(c *fiber.Ctx) {
c.Write("Match exact path /api/user\n")
})
// Start server on http://localhost:8080
app.Listen(8080)
}
```
## API Documentation
We created an extended API documentation including examples, **[click here](https://gofiber.github.io/fiber/)**
We created an extended API documentation including examples, **[click here](https://gofiber.github.io/fiber/)**.
## Stargazers over time
[![Stargazers over time](https://starchart.cc/gofiber/fiber.svg)](https://starchart.cc/gofiber/fiber)
## License
gofiber/fiber is free and open-source software licensed under the [MIT License](https://github.com/gofiber/fiber/edit/master/LICENSE).
☝️ _Please note:_ `gofiber/fiber` is free and open-source software licensed under the [MIT License](https://github.com/gofiber/fiber/edit/master/LICENSE).
*Caught a mistake? [Edit this page on GitHub!](https://github.com/gofiber/fiber/blob/master/README.md)*