Skip to content

About

Http server created with Netty

Resources

Stars

1 star

Watchers

1 watching

Forks

Repository files navigation

Web Server using Netty

This is a simple web server using Netty. It is a minimalistic implementation of a web server that can serve a REST API. This project is created for learning purposes and aims to provide a framework for creating web servers using Netty without relying on Jakarta EE or Spring.

Table of Contents

Introduction

Netty is an asynchronous event-driven network application framework for rapid development of maintainable high-performance protocol servers and clients. This project aims to simplify the process of creating web servers using Netty by providing a framework inspired by the Laravel style of coding.

Features

  • HTTP Methods

    • GET request
    • POST request
    • PUT request
    • DELETE request
    • PATCH request
  • Routing

    • Lambda-based routing
    • Controller-based routing
    • Route groups
    • Route prefixes
    • Route naming
    • Resource routing
  • Request Handling

    • URL parameters
    • Query parameters
    • Request body parsing
    • File uploads
    • Form data handling
    • Request validation
  • Response

    • JSON responses
    • Response Class
    • File responses
    • Stream responses
    • Custom response headers
    • Response compression
    • Content negotiation
  • Security

    • CORS support
    • Session management
    • Basic authentication
    • JWT authentication
    • Rate limiting
    • CSRF protection
    • XSS protection
  • Middleware

    • Global middleware
    • Route middleware
    • Middleware groups
    • Error handling middleware
  • Database

    • Database connection management
    • Basic ORM functionality
    • Query builder
    • Migrations
    • Model relationships
  • Caching

    • In-memory cache
    • File cache
    • Redis integration
    • Cache tags
    • Cache invalidation
  • Development Tools

    • Request logging
    • Performance monitoring
    • Hot reload
    • Configuration management
    • Environment management

Installation

To set up the project, follow these steps:

  1. Clone the repository:

    git clone https://github.com/henimbola/netty-webhttp.git
    cd netty-webhttp
  2. Build the project using Gradle:

    ./gradlew build

Usage

Here are some examples of how to use the web server:

Define Routes

package webhttp;

import webhttp.library.Router;

public class Main {
    public static void main(String[] args) throws Exception {
        Router.get("/", req -> new Message("Hello, World!"));
        Router.get("/message", req -> new Message("Hello, World!"));
        Router.post("/message", req -> new Message("Hello, World!"));
        Router.get("/routes", req -> HttpRouter.getRoutes());
        Router.get("/testmap", req -> Map.of("message", "Hello, World!", "status", 200));

        WebHttpApplication.run(8080);
    }
}

Controller Based Routing

Create a controller class:

package webhttp.controller;

public class MessageController extends Controller {
    
    public Object index() {
        return new Message("Hello, World!");
    }
}
public class Main {
    public static void main(String[] args) throws Exception {
        // Controller routes
        Router.get("/messages", MessageController.class, "index");        
        WebHttpApplication.run(8080);
    }
}

About

Http server created with Netty

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages