Welcome to Fiber — an Express.js styled web framework written in Go with ️
Tags: go, node, fiber, tutorial
Published: 2020-02-03 22:41:55

## Introduction

Hello, World! 👋 Today we will deal with a young (but ambitious) **Fiber web framework** on Go and understand that this is not "_yet another new framework, like X_", but a great tool for creating rapid web applications.

> 📌 It will be a review article, dive into Fiber we will start further.

### Table of contents

1. [What is Fiber and why is it so good?](#ch-1)
2. [Useful information to start working with Fiber](#ch-2)
3. [Main features](#ch-3)
4. [Benchmarks](#ch-4)
5. [Project assistance](#ch-5)

<a name="ch-1"></a>
## What is Fiber and why is it so good?

Follow official [README](https://github.com/gofiber/fiber) from GitHub repository:

> Fiber is an Express.js 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.

And I tend to agree with that. If you have ever implemented a web application on Node.js using [Express.js](https://expressjs.com) (like me), then many methods and principles will seem very common to you!

For example, this is standard `Hello, World!` by Express.js:

```js
// ...

const app = express()

app.get('/', (req, res) => res.send('Hello, World!'))

app.listen(8080)
```

And similar example by [Fiber](https://github.com/gofiber/fiber):

```go
// ...

app := fiber.New()

app.Get("/", func(c *fiber.Ctx) {
  c.Send("Hello, World!")
})

app.Listen(8080)
```

<a name="ch-2"></a>
## Useful information to start working with Fiber

Actually, all you need for start is [official documentation](https://docs.gofiber.io)! 😉

Fiber, _as a web framework_, was created with _idea of minimalism_ to more easily start creating a web application's backend for new **gophers**, but who have experience with JavaScript.

That's what the authors themselves say:

> People switching from Node.js to Go 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.

![main features](https://dev-to-uploads.s3.amazonaws.com/i/6o9c321we8s1bdsm87p3.jpg)

<a name="ch-3"></a>
## Main features 

- 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
- [Extended documentation](https://docs.gofiber.io)

### Easy to enable the prefork feature

Just set `Prefork` to `true` on your code:

```go
// ...

app := fiber.New()

app.Prefork = true // enable prefork

app.Get("/", func(c *fiber.Ctx) {
  c.Send(fmt.Sprintf("Hi, I'm worker #%v", os.Getpid()))
  // => Hi, I'm worker #16858
  // => Hi, I'm worker #16877
  // => Hi, I'm worker #16895
})

app.Listen(8080)
```

#### What's prefork?

Enable prefork feature will spawn multiple go processes listening on the same port. **Nginx** has a great article about [Socket Sharding](https://www.nginx.com/blog/socket-sharding-nginx-release-1-9-1/), this picture are taken from the same article 👇

![prefork](https://cdn.wp.nginx.com/wp-content/uploads/2015/05/Slack-for-iOS-Upload-e1432652376641.png)

### ✨ My favorite killer feature ✨

And one more big feature (for me) is **full access** to all Fasthttp methods and properties (read [documentation](https://pkg.go.dev/github.com/valyala/fasthttp?tab=doc) for more info about it).

> _Yeah, you didn't mishear!_ Fiber is extremely easy to use as **Express.js** and has everything under the hood that **Fasthttp** has now and will have in the future 🔥

<a name="ch-4"></a>
## Benchmarks 🤖

[Click here](https://docs.gofiber.io/extra/benchmarks) to see all benchmark results. I'll only bring some.

- TechEmpower: JSON serialization 

![JSON serialization](https://dev-to-uploads.s3.amazonaws.com/i/r4crydf32c0l3odp779c.png)

- Go-Web: enable HTTP pipelining

![enable http pipelining](https://dev-to-uploads.s3.amazonaws.com/i/exprrvdk9dttot0zcqjl.png)

<a name="ch-5"></a>
## Project assistance

1. Add a [GitHub Star](https://github.com/gofiber/fiber) to project.
2. Tweet about project [on your Twitter](https://twitter.com/intent/tweet?text=%F0%9F%9A%80%20Fiber%20is%20an%20Express%20inspired%20web%20framework%20written%20in%20%23Go%20with%20%F0%9F%92%96%20https%3A%2F%2Fgithub.com%2Fgofiber%2Ffiber).
3. Help to translate README and [API Docs](https://docs.gofiber.io) to another language.

## Photo by

[Title] Fiber Authors https://gofiber.io/
[1] Nate Grant https://unsplash.com/photos/dFF8z3WH5FI

<a name=""></a>
## P.S.

If you want more articles (like this) on this blog, then post a comment below and subscribe to me. Thanks! 😻

And of course, you can help me make developers' lives even better! Just connect to one of my projects as a contributor. It's easy!

My projects that need your help (and stars) 👇

- 🔥 [gowebly][gowebly_url]: A next-generation CLI tool for easily build amazing web applications with Go on the backend, using htmx & hyperscript and the most popular atomic/utility-first CSS frameworks on the frontend.
- ✨ [create-go-app][cgapp_url]: Create a new production-ready project with Go backend, frontend and deploy automation by running one CLI command.
- 🏃 [yatr][yatr_url]: Yet Another Task Runner allows you to organize and automate your routine operations that you normally do in Makefile (or else) for each project.
- 📚 [gosl][gosl_url]: The Go Snippet Library provides snippets collection for working with routine operations in your Go programs with a super user-friendly API and the most efficient performance.
- 🏄‍♂️ [csv2api][csv2api_url]: The parser reads the CSV file with the raw data, filters the records, identifies fields to be changed, and sends a request to update the data to the specified endpoint of your REST API.
- 🚴 [json2csv][json2csv_url]: The parser can read given folder with JSON files, filtering and qualifying input data with intent & stop words dictionaries and save results to CSV files by given chunk size.

<!-- Footer links -->

[gowebly_url]: https://github.com/gowebly
[cgapp_url]: https://github.com/create-go-app
[yatr_url]: https://github.com/koddr/yatr
[gosl_url]: https://github.com/koddr/gosl
[csv2api_url]: https://github.com/koddr/csv2api
[json2csv_url]: https://github.com/koddr/json2csv