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_OPTIONSBuilt-in support for AI integration with Model Context Protocol (MCP):
# MCP configuration in config.properties
mcp.auth.token=your_token_here
Benefits:
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:
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:
Enhanced support for multiple HTTP servers with improved performance:
Netty Server (Recommended)
bin/dispatcher start --import org.tinystruct.system.NettyHttpServer
Tomcat Server
bin/dispatcher start --import org.tinystruct.system.TomcatServer
Undertow Server
bin/dispatcher start --import org.tinystruct.system.UndertowServer
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:
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.MyApp
Same 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/John
Clean 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 closed
Version 1.7.19 maintains backward compatibility with previous 1.8.x versions. All existing code should continue to work without modifications.
<dependency>
<groupId>org.tinystruct</groupId>
<artifactId>tinystruct</artifactId>
<version>1.7.19</version>
</dependency>
// 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() { ... }
# config.properties
mcp.auth.token=your_token_here
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!