This document highlights the new features, improvements, and changes introduced in tinystruct version 1.7.19.
You can now specify which HTTP methods an action responds to, enabling proper RESTful API design:
@Action(value = "users", mode = Mode.HTTP_GET)
public String getUsers() {
return userService.findAll().toString();
}
@Action(value = "users", mode = Mode.HTTP_POST)
public String createUser(Request request) {
String name = request.getParameter("name");
return userService.create(name).toString();
}
@Action(value = "users", mode = Mode.HTTP_PUT)
public String updateUser(Integer id, Request request) {
String name = request.getParameter("name");
return userService.update(id, name).toString();
}
@Action(value = "users", mode = Mode.HTTP_DELETE)
public String deleteUser(Integer id) {
userService.delete(id);
return "User deleted";
}Available HTTP Method Modes:
Mode.HTTP_GETMode.HTTP_POSTMode.HTTP_PUTMode.HTTP_DELETEMode.HTTP_PATCHMode.HTTP_HEADMode.HTTP_OPTIONS
Built-in support for AI integration with Model Context Protocol (MCP):
# MCP configuration in config.properties
mcp.auth.token=your_token_hereBenefits:
- Easy integration with AI models
- Standardized protocol for model communication
- Plugin-based architecture for AI extensions
- Support for custom AI providers
Example AI Integration:
@Action("ai/chat")
public String chat(String message) {
// Use MCP to communicate with AI models
return aiService.chat(message);
}Native support for Server-Sent Events for real-time data streaming:
@Action(value = "stream", mode = Mode.HTTP_GET)
public void streamData(Request request, Response response) {
response.setHeader("Content-Type", "text/event-stream");
response.setHeader("Cache-Control", "no-cache");
// Stream real-time data
while (shouldContinue()) {
String data = getLatestData();
response.write("data: " + data + "\n\n");
response.flush();
Thread.sleep(1000);
}
}Use Cases:
- Real-time notifications
- Live data feeds
- Progress updates
- Chat applications
- Stock tickers
Improved modular design for plugin-based applications:
// Plugin interface
public interface Plugin {
void initialize(Application app);
void start();
void stop();
}
// Plugin implementation
public class MyPlugin implements Plugin {
@Override
public void initialize(Application app) {
// Plugin initialization
}
}Benefits:
- Dynamic plugin loading
- Hot-swappable components
- Extensible architecture
- Isolated plugin contexts
Enhanced support for multiple HTTP servers with improved performance:
Netty Server (Recommended)
bin/dispatcher start --import org.tinystruct.system.NettyHttpServer- 86,000+ requests/second
- Async I/O
- WebSocket support
- SSE support
Tomcat Server
bin/dispatcher start --import org.tinystruct.system.TomcatServer- Traditional servlet support
- JSP support
- Enterprise compatibility
Undertow Server
bin/dispatcher start --import org.tinystruct.system.UndertowServer- Lightweight footprint
- Non-blocking I/O
- Embedded-friendly
Version 1.7.19 achieves exceptional performance:
Running 30s test @ http://127.0.0.1:8080/?q=say/Praise the Lord!
12 threads and 400 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 17.44ms 33.42ms 377.73ms 88.98%
Req/Sec 7.27k 1.66k 13.55k 69.94%
2,604,473 requests in 30.02s, 524.09MB read
Requests/sec: 86,753.98
Transfer/sec: 17.46MB
Key Metrics:
- Throughput: 86,753 requests/second
- Latency: 17.44ms average
- Consistency: 88.98% within one standard deviation
- Memory: 524MB over 30 seconds (17.46MB/s)
-
Zero Overhead Architecture
- No reflection-based bean scanning
- Direct method invocation
- Minimal interceptor chain
-
Efficient Memory Management
- Small memory footprint
- No excessive object creation
- Optimized garbage collection
-
Smart Routing
- Compiled pattern matching
- Fast URL parsing
- Cached route resolution
Applications can be started directly without a main() method:
// No main() method needed!
public class MyApp extends AbstractApplication {
@Override
public void init() {
// Just initialization
}
}Start with CLI:
bin/dispatcher start --import com.example.MyAppSame code works for both CLI and Web:
@Action(value = "greet", mode = Mode.ALL)
public String greet(String name) {
return "Hello, " + name + "!";
}
// CLI: bin/dispatcher greet/John
// Web: http://localhost:8080/?q=greet/JohnClean separation of concerns:
Application Layer
↓
Action Layer (Routes/Commands)
↓
Service Layer (Business Logic)
↓
Repository Layer (Data Access)
↓
Database Layer
Improved JSON building with Builder class:
Builder builder = new Builder();
builder.put("success", true);
builder.put("data", dataObject);
builder.put("timestamp", System.currentTimeMillis());
// Nested objects
Builder nested = new Builder();
nested.put("id", 123);
nested.put("name", "John");
builder.put("user", nested);
// Arrays
Builders array = new Builders();
array.add("item1");
array.add("item2");
builder.put("items", array);
String json = builder.toString();Enhanced database operations with better resource management:
try (DatabaseOperator operator = new DatabaseOperator()) {
// Automatic resource cleanup
ResultSet results = operator.query("SELECT * FROM users");
// Process results
} // Resources automatically closedVersion 1.7.19 maintains backward compatibility with previous 1.8.x versions. All existing code should continue to work without modifications.
-
Update Maven Dependency
<dependency> <groupId>org.tinystruct</groupId> <artifactId>tinystruct</artifactId> <version>1.7.19</version> </dependency>
-
Optional: Use New HTTP Method-Specific Actions
// Old way (still works) @Action("users") public String getUsers() { ... } // New way (recommended for RESTful APIs) @Action(value = "users", mode = Mode.HTTP_GET) public String getUsers() { ... }
-
Optional: Add MCP Configuration
# config.properties mcp.auth.token=your_token_here
- GitHub: https://github.com/tinystruct/tinystruct
- Documentation: https://tinystruct.org
- Examples: https://github.com/tinystruct/tinystruct-examples
- Archetype: https://github.com/tinystruct/tinystruct-archetype
- Smalltalk (AI Chat): https://github.com/tinystruct/smalltalk
- Enhanced reactive programming support
- GraphQL integration
- gRPC support
- Kubernetes native features
- Enhanced monitoring and metrics
- WebAssembly support
Version 1.7.19 represents a significant step forward for the tinystruct framework, adding modern features like HTTP method-specific actions, AI integration, and SSE support while maintaining the framework's core philosophy of simplicity, performance, and ease of use.
The framework continues to deliver exceptional performance (86,000+ req/s) while remaining lightweight and developer-friendly. With no main() method required and unified CLI/Web support, tinystruct makes Java application development faster and more enjoyable.
Try it today and experience the difference!