DEV Community

Cover image for Mantis, a web framework written in V
Anwar
Anwar

Posted on

Mantis, a web framework written in V

Tired of runtime errors in production? Meet Mantis: a type-safe web framework that helps you catch bugs at compile time, built with the simplicity of V.

Summary

What is V?

V is a new general-purpose, type-safe functional programming language.

Its syntax draws inspiration from the simplicity of Go.

V emphasizes simplicity and explicitness at its core, making it straightforward to write and understand.

You can learn V's basics in about an hour by reading the documentation, allowing you to quickly start building your first hello world app.

Like Go, Deno, and Rust, V produces executables that run on Linux, Mac, and Windows.

What I love most about V is its first-class support for Result and Option types (abstract data types that we'll explore later).

With V, the lightning-fast compiler guides you to write safer code. When your app compiles, you can be confident it won't encounter runtime errors in production.

For development, V offers both an interpreter and watch mode, combining the convenience of scripting languages with the type safety and performance of compiled languages. It even includes built-in channel-compatible concurrency - truly the best of both worlds.

Who is Mantis for?

Mantis is a server-side rendered web framework for building web apps and APIs. It's ideal for:

  • Teams seeking type safety without complexity
  • Developers familiar with Go/Rust who want a simpler alternative for web apps
  • Projects requiring long-term maintainable applications
  • Developers tired of catching bugs in production

A tour of Mantis

Mantis offers a fresh approach to building APIs and web apps.

The framework prioritizes expressive, explicit code to create maintainable codebases.

It provides sensible defaults for common patterns like session handling and i18n.

Here's a simple hello world app:

module main

import khalyomede.mantis.http { create_app, App, Response }
import khalyomede.mantis.http.route
import khalyomede.mantis.http.response

fn main() {
  app := create_app(
    routes: [
      route.get(name: "index", path: "/", callback: fn (app App) Response {
        return response.html(content: "hello world")
      })
    ]
  )

  app.serve() or { panic(err) }
}
Enter fullscreen mode Exit fullscreen mode

All of the features are documented on the official documentation so make sure to give it a check.

Quick start

Get started with your first Mantis web app by following our Quick Start guide!

A note on type safety

V offers first-party support for Result/Option types.

These types are data representation of an outcome that can fail or succeed (Result), or an outcome that can be found or not (Option, often called Maybe in other programming language).

For example, here is how this patterns is used when getting route parameters:

module main

import khalyomede.mantis.http { create_app, App, Response }
import khalyomede.mantis.http.route
import khalyomede.mantis.http.response

fn main() {
  app := create_app(
    routes: [
      route.get(
        name: "post.show"
        path: "/post/{id}"
        callback: fn (app App) Response {
          id := app.route_parameter("id") or {
            return response.html(content: "Post not found")
          }

          return response.html(content: "Showing post ${id}")
        }
      )
    ]
  )

  app.serve() or { panic(err) }
}
Enter fullscreen mode Exit fullscreen mode

Why another framework?

My background includes building web apps with Laravel (PHP) and Javascript.

Throughout my career, I encountered the limitations of Object Oriented Programming and discovered the elegance of Functional Programming. This led me to appreciate concepts like exhaustive pattern matching, Abstract Data Types, and explicit code that prevents uncaught exceptions.

I began searching for tools that could catch bugs at compile time rather than in production. After exploring many modern programming languages, I found my match in V's simplicity and reliability.

Mantis combines the productivity I enjoyed with other frameworks with V's advantages.

I hope this project helps others discover V's benefits and build more reliable applications, bringing back the joy of simple programming.

Mantis aims to help you focus on business needs by providing good defaults while maintaining long-term code maintainability.

We intentionally avoid complex patterns, staying light on opinions. You won't find Repositories or ORMs here (though we plan to add a database-specific query builder - see our roadmap), keeping the framework simple yet effective.

Veb

Veb is V's official web framework, offering different features from Mantis:

Consider reviewing Veb's documentation to determine which framework better suits your needs.

Conclusion

I hope this introduction has piqued your interest in this fresh approach. While some may question it, others might find it intriguing, and hopefully, some will give it a try.

Feel free to explore more at khalyomede.github.io/mantis and share your thoughts in the comments!

Join us on the V Discord where I'll be happy to answer your questions!

Your ideas, suggestions, and bug reports are welcome in our issue tracker - every contribution helps!

Happy coding!

Top comments (0)