DEV Community

Bakemono
Bakemono

Posted on

Introducing Gofsen: A Clean & Minimalist Web API Framework for Go

Hi everyone! After weeks of development, I'm excited to officially launch Gofsen — a new web framework for building fast and maintainable REST APIs in Go.

👉 GitHub Repo

GitHub logo Bakemono-san / gofsen

A fast, idiomatic API framework for Go, built in Senegal.

🚀 Gofsen - HTTP Framework for Go

Go Version GitHub release Go Report Card License GoDoc

Gofsen is a lightweight, Express.js-inspired HTTP framework for Go. Simple, fast, and powerful.


📦 Installation

go get github.com/Bakemono-san/gofsen
Enter fullscreen mode Exit fullscreen mode

🚀 Quick Start

package main

import "github.com/Bakemono-san/gofsen"

func main() {
    app := gofsen.New()
    
    app.GET("/", func(c *gofsen.Context) {
        c.JSON(map[string]string{
            "message": "Hello Gofsen!",
            "version": gofsen.Version,
        })
    })
    
    app.Listen("8080")
}
Enter fullscreen mode Exit fullscreen mode

✨ Features

✅ HTTP Routing

  • HTTP Methods: GET, POST, PUT, DELETE, PATCH
  • Route Parameters: /users/:id
  • Route Groups: /api/v1
  • Query Parameters: ?name=value

✅ Middleware System

  • Logger: Automatic request logging
  • Recovery: Panic recovery
  • CORS: Complete CORS support with configuration
  • Custom Middleware: Create your own middlewares

✅ Request/Response Helpers

  • JSON: Automatic parsing and sending
  • Query Params: Easy…

🧠 Why Gofsen?

Gofsen was built out of a simple need: create clean, maintainable, and idiomatic APIs in Go — without boilerplate or over-engineered abstractions.

Other frameworks like Gin, Echo, or Fiber are great, but sometimes you just want:

  • ✅ Clear routing
  • ✅ Simple middleware chaining
  • ✅ Route groups (/api/v1)
  • ✅ Dynamic params (/users/:id)
  • ✅ JSON helpers and error handling
  • ✅ No reflection, no magic

That's where Gofsen shines.


✨ Features

  • HTTP Routing: GET, POST, PUT, DELETE, PATCH
  • Route Parameters: /users/:id
  • Route Groups: /api/v1, with local middleware
  • Global & Custom Middleware
  • Request Helpers: JSON, query params, errors
  • Built-in Middleware: CORS, Logging, Recovery
  • ✅ Built in Go with ❤️ from Senegal 🇸🇳

🧪 Quick Start

Try it out right now! Here's a complete working example:

// This would be a Go example if RunKit supported Go // For now, here's the conceptual JavaScript equivalent const express = require('express'); const app = express(); app.get('/hello', (req, res) => { res.json({ message: 'Hello from Gofsen (Go equivalent)' }); }); app.listen(8080, () => { console.log('🚀 Server running on port 8080'); });

And here's the actual Gofsen Go code:

package main

import (
    "github.com/Bakemono-san/gofsen"
)

func main() {
    r := gofsen.New()

    r.GET("/hello", func(ctx *gofsen.Context) {
        ctx.Status(200).JSON(map[string]string{"message": "Hello from Gofsen"})
    })

    r.Listen("8080")
}
Enter fullscreen mode Exit fullscreen mode

🚀 Route Parameters & Groups

package main

import (
    "github.com/Bakemono-san/gofsen"
)

func main() {
    r := gofsen.New()

    // Simple route with parameter
    r.GET("/users/:id", func(ctx *gofsen.Context) {
        userID := ctx.Param("id")
        ctx.Status(200).JSON(map[string]string{
            "user_id": userID,
            "message": "User details",
        })
    })

    // Route groups
    api := r.Group("/api/v1")
    api.GET("/posts", func(ctx *gofsen.Context) {
        ctx.Status(200).JSON(map[string]string{"message": "All posts"})
    })

    api.POST("/posts", func(ctx *gofsen.Context) {
        var post map[string]interface{}
        if err := ctx.BindJSON(&post); err != nil {
            ctx.Error(400, "Invalid JSON")
            return
        }
        ctx.Status(201).JSON(map[string]interface{}{
            "message": "Post created",
            "post":    post,
        })
    })

    r.Listen("8080")
}
Enter fullscreen mode Exit fullscreen mode

🧩 Middleware Example

package main

import (
    "github.com/Bakemono-san/gofsen"
)

// Custom Auth Middleware
func AuthMiddleware() gofsen.MiddlewareFunc {
    return func(ctx *gofsen.Context) {
        token := ctx.Request.Header.Get("Authorization")
        if token != "Bearer valid-token" {
            ctx.Error(401, "Unauthorized")
            return
        }
        ctx.Next()
    }
}

func main() {
    r := gofsen.New()

    // Global middleware
    r.Use(gofsen.Logger())
    r.Use(gofsen.Recovery())
    r.Use(gofsen.CORS())

    // Public routes
    r.GET("/", func(ctx *gofsen.Context) {
        ctx.Status(200).JSON(map[string]string{"message": "Welcome to Gofsen!"})
    })

    // Protected API group
    api := r.Group("/api")
    api.Use(AuthMiddleware()) // Apply auth to this group only

    api.GET("/me", func(ctx *gofsen.Context) {
        ctx.Status(200).JSON(map[string]string{
            "user":    "authenticated_user",
            "message": "This is a protected route",
        })
    })

    r.Listen("8080")
}
Enter fullscreen mode Exit fullscreen mode

🌐 Installation

go get github.com/Bakemono-san/gofsen
Enter fullscreen mode Exit fullscreen mode

Import it in your project:

import "github.com/Bakemono-san/gofsen"
Enter fullscreen mode Exit fullscreen mode

🔧 Coming Soon

🛠️ A CLI is on the way to scaffold new Gofsen apps

gofsen new my-api
gofsen generate handler user
Enter fullscreen mode Exit fullscreen mode

Want to see the roadmap?

🚀 Upcoming Features:

  • CLI tool for project scaffolding
  • Built-in validation middleware
  • Template rendering support
  • WebSocket support
  • Database integration helpers
  • Performance monitoring middleware
  • Auto-generated API documentation


🙌 Get Involved

Gofsen is 100% open-source and actively developed.

⭐ Star Gofsen on GitHub

  • 🐛 Report issues
  • 🚀 Contribute features or fixes
  • 📢 Share it if you find it useful!

👉 https://github.com/Bakemono-san/gofsen


Thanks for reading, and happy hacking with Go! 🦫

Tags: #golang #go #api #webdev #opensource #framework #gofsen #backend #devtools

Top comments (1)

Collapse
 
fallou44 profile image
serigne fallou seck

GOAT waiting for the next step