From 79675954af150a03dfa83dbebcf024443a2f6bf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vic=20Sh=C3=B3stak?= Date: Sat, 7 Mar 2020 17:34:42 +0300 Subject: [PATCH] Update README.md --- .github/README.md | 138 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 102 insertions(+), 36 deletions(-) diff --git a/.github/README.md b/.github/README.md index ef52bcf9..f676e24a 100644 --- a/.github/README.md +++ b/.github/README.md @@ -4,37 +4,37 @@
- + - + - + - + - + - + - + - + - + - +

@@ -129,6 +129,12 @@ Listed below are some of the common examples. If you want to see more code examp ### Routing +Docs: + +- 📖 https://fiber.wiki/#basic-routing + +Example: + ```go func main() { app := fiber.New() @@ -156,7 +162,13 @@ func main() { ``` ### Serve static files -https://fiber.wiki/application#static + +Docs: + +- 📖 https://fiber.wiki/application#static + +Example: + ```go func main() { app := fiber.New() @@ -177,8 +189,14 @@ func main() { ``` ### Middleware & Next -https://fiber.wiki/routing#middleware -https://fiber.wiki/context#next + +Docs: + +- 📖 https://fiber.wiki/routing#middleware +- 📖 https://fiber.wiki/context#next + +Example: + ```go func main() { app := fiber.New() @@ -209,16 +227,22 @@ func main() { 📚 Show more code examples ### Template engines -https://fiber.wiki/application#settings -https://fiber.wiki/context#render + +Docs: + +- 📖 https://fiber.wiki/application#settings +- 📖 https://fiber.wiki/context#render Supported engines: + - [html](https://golang.org/pkg/html/template/) - [amber](https://github.com/eknkc/amber) - [handlebars](https://github.com/aymerick/raymond) - [mustache](https://github.com/cbroglie/mustache) - [pug](https://github.com/Joker/jade) +Example: + ```go func main() { // You can setup template engine before initiation app: @@ -246,7 +270,13 @@ func main() { ``` ### Grouping routes into chains -https://fiber.wiki/application#group + +Docs: + +- 📖 https://fiber.wiki/application#group + +Example: + ```go func main() { app := fiber.New() @@ -269,7 +299,13 @@ func main() { ``` ### Middleware logger -https://fiber.wiki/middleware#logger + +Docs: + +- 📖 https://fiber.wiki/middleware#logger + +Example: + ```go import ( "github.com/gofiber/fiber" @@ -293,9 +329,14 @@ func main() { ``` ### Cross-Origin Resource Sharing (CORS) -https://fiber.wiki/middleware#cors -[CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS) is a mechanism that uses additional HTTP headers to tell browsers to give a web application running at one origin, access to selected resources from a different origin. A web application executes a cross-origin HTTP request when it requests a resource that has a different origin (domain, protocol, or port) from its own. +Docs: + +- 📖 https://fiber.wiki/middleware#cors + +> [CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS) is a mechanism that uses additional HTTP headers to tell browsers to give a web application running at one origin, access to selected resources from a different origin. A web application executes a cross-origin HTTP request when it requests a resource that has a different origin (domain, protocol, or port) from its own. + +Example: ```go import ( @@ -310,7 +351,7 @@ func main() { app.Use(middleware.CORS()) app.Get("/", func(c *fiber.Ctx) { - c.Send("CORS is enabled!") + c.Send("CORS is enabled!") }) app.Listen(3000) @@ -325,6 +366,12 @@ curl -H "Origin: http://example.com" --verbose http://localhost:3000 ### Custom 404 response +Docs: + +- 📖 https://fiber.wiki/application#http-methods + +Example: + ```go func main() { app := fiber.New() @@ -341,7 +388,8 @@ func main() { // Last middleware to match anything app.Use(func(c *fiber.Ctx) { - c.SendStatus(404) // => 404 "Not Found" + c.SendStatus(404) + // => 404 "Not Found" }) app.Listen(3000) @@ -349,7 +397,13 @@ func main() { ``` ### JSON Response -https://fiber.wiki/context#json + +Docs: + +- 📖 https://fiber.wiki/context#json + +Example: + ```go type User struct { Name string `json:"name"` @@ -361,15 +415,15 @@ func main() { app.Get("/user", func(c *fiber.Ctx) { c.JSON(&User{"John", 20}) - // {"name":"John", "age":20} + // => {"name":"John", "age":20} }) app.Get("/json", func(c *fiber.Ctx) { - c.JSON(&fiber.Map{ - "success": true, - "message": "Hi John!", + c.JSON(fiber.Map{ + "success": true, + "message": "Hi John!", }) - // {"success":true, "message":"Hi John!"} + // => {"success":true, "message":"Hi John!"} }) app.Listen(3000) @@ -377,7 +431,13 @@ func main() { ``` ### WebSocket support -https://fiber.wiki/application#websocket + +Docs: + +- 📖 https://fiber.wiki/application#websocket + +Example: + ```go func main() { app := fiber.New() @@ -406,7 +466,13 @@ func main() { ``` ### Recover middleware -https://fiber.wiki/middleware#recover + +Docs: + +- 📖 https://fiber.wiki/middleware#recover + +Example: + ```go package main @@ -455,12 +521,6 @@ If you want to say **thank you** and/or support the active development of `Fiber - +
- -
- JustDave -
-

@@ -485,6 +545,12 @@ If you want to say **thank you** and/or support the active development of `Fiber ToishY
+ +
+ JustDave +
+