Welcome to Fiber โ€” an Express.js styled web framework written in Go๐ŸŽ‰

Welcome to Fiber โ€” an Express.js styled web framework written in Go๐ŸŽ‰

A amazing Tutorial series for understanding the Fiber Web Framework and building crazy stuff :)

ยท

3 min read

Introduction :

Hey there ๐Ÿ‘‹, today we are going to start with a very young and exciting Fiber Web Framework that is written in Golang. It is a great tool for creating Rapid Web Applications.

Useful Information ๐Ÿ’ฏ:

Fiber is an Express.js styled HTTP web framework implementation running on Fasthttp, the fastest HTTP engine for Go (Golang). The package makes use of a similar framework convention as they are in Express.

It was created with the idea of minimalism to more easily start creating a web application's backend for experienced as well as new gophers.

For more detailed information you just need official documentation ๐Ÿ™‚

Getting Started ๐Ÿ’ป:

Let's start the implementation using Fiber. First of all, you need to install Fiber.

Initializing :

Before that make a repository for eg. go-fiber-series , Now initialize a mod file. (If you publish a module, this must be a path from which your module can be downloaded by Go tools. That would be your code's repository.)

go mod init github.com/Siddheshk02

Instead Siddheshk02 use the directory name inside which all the project repos are.

Now, for installing fiber run the following command ๐Ÿš€:

go get github.com/gofiber/fiber/v2

Make a new file main.go in the same folder. Now we'll just try a simple program using Fiber Framework ๐Ÿš€

Write the following code in the main.go file (It is better to write/Type instead of just copy-pasting)๐Ÿ™‚

package main

import (
    "github.com/gofiber/fiber/v2"
)

func main() {

    app := fiber.New()

    app.Get("/", func(c *fiber.Ctx) error {
        return c.SendString("Hello World!!, This is Go-Fiber Tutorial Series")
    })

    app.Listen(":8080")

}

Now, let's understand what this code means :)

app is an instance of Fiber, fiber.New() creates a new instance.

app.Method(path string, ...func(*fiber.Ctx) error) This is how the route is defined in fiber

Method is an HTTP Request Method : GET, PUT, POST, etc.

path is a virtual path on the server.

func(*fiber.Ctx) error is a callback function containing the context executed when the route is matched.

return c.SendString(" ") send the message with the Request.

Here the message is : "Hello World!!, This is Go-Fiber Tutorial Series"

app.Listen() starts the server at the given port.

Now, run the main.go file. For that run the command go run main.go .

Output โœจ๐Ÿš€:

After running the main.go the output will look like the above-given image.

When you follow the given link i.e. http://127.0.0.1:8080 the message will be displayed ๐Ÿ™‚

You can find the complete repository for this tutorial here ๐Ÿ‘‰ Github

Conclusion ๐Ÿ’ฏ:

I hope you must have got a basic understanding of the fiber web framework and how to get started with it through this tutorial.

In the next upcoming tutorial, you will learn some advanced topics and concepts of the young Fiber Web Framework along with building some crazy stuff ๐ŸŽ‰

To get more information about Golang concepts, projects, etc. and to stay updated on the Tutorials do follow Siddhesh on Twitter and GitHub.

Until then Keep Learning, Keep Building ๐Ÿš€๐Ÿš€

ย