The Diego Web Framework

The Diego Web Framework #

A minimal web framework for creating web applications with Java and Groovy.

This framework does not intend to be an all-encompassing web framework, but a distillation of specific features that are very common in developing web-based internal tools and applications - a framework for the 90% use case, if you will.

The end result is a tool that facilitates rapid application development, that is easy to learn, and provides a familiar experience to developers coming from an Express/Koa background.

Getting Started #

Download and extract the starter project and open it with your IDE of choice.

Your first application #

In your project, open the src/main/groovy/Server.groovy file.

Let’s take a look at how we can create a simple application that echoes “Hello, world!” when visited.

import diego.Application
import diego.Diego
import diego.web.Router

class Server extends Application {

    void configure(Router router) {
        router.get("/", (req, res) -> res.ok().send("Hello, world!"))
    }

    static void main(String[] args) {
        Diego.run(Server)
    }
}

This code should look very familiar to anyone with experience in Express or Koa.

Starting the application #

From the root of the project, run the following command:

scripts/start

This will start the application in Super Dev ⚡ mode.

In Super Dev mode, source files are watched for changes and the application is rebuilt and reloaded when a change is detected.

When the application has ready, it should be accessible at http://localhost:8080.

You can also provide a class name to the start script if you prefer not to move/rename the Server class in the default package.

The application will listen on port 8080 by default, but you can choose the port in a few ways. See the Configuration chapter for details.

Next: Routing