Skip to main content

Command Palette

Search for a command to run...

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 :)

Published
β€’3 min read
Welcome to Fiber β€” an Express.js styled web framework written in GoπŸŽ‰
S

I am a Developer experienced in building Web Apps and CLI using Golang. I'm also experienced in Laravel development

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 πŸš€πŸš€

Go-Fiber Web Framework Tutorial

Part 1 of 6

In this series , I will give you all a brief introduction to Fiber Web Framework and how to get started with it. Further in the series we'll learn by building mini projects using Go-Fiber Framework

Up next

Building CRUD Operations in Golang πŸŽ‰

Creating a REST-API using Go, Fiber, PostgreSQL DB and GORM.