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.
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.
-
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
To set up the project, follow these steps:
-
Clone the repository:
git clone https://github.com/henimbola/netty-webhttp.git cd netty-webhttp -
Build the project using Gradle:
./gradlew build
Here are some examples of how to use the web server:
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);
}
}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);
}
}