minum
v8.0.5
當您需要最少的活動部件時
最簡單的小程序(請參見下面的更多代碼示例):
public class Main {
public static void main ( String [] args ) {
var minum = FullSystem . initialize ();
var wf = minum . getWebFramework ();
wf . registerPath ( GET , "" ,
r -> Response . htmlOk ( "<p>Hi there world!</p>" ));
minum . block ();
}
}該網絡框架“ Minum”為Web應用程序提供了全功率的極簡主義基礎。對於TDD,由TDD。
make test_coverage )make mutation_test )Minum是五千行代碼 - “極簡主義”競爭對手在佔其依賴性時從40萬到700,000行不等。我還沒有找到類似的項目。
採用極簡主義方法可以更輕鬆地調試,可維護性和降低總成本。大多數框架以更高的總體成本交易速度。如果您需要可持續的質量,則必須從一開始就經過良好的測試和記錄。例如,這個項目的實現如此高的測試覆蓋範圍的能力是極簡主義範式實現的。
有一個快速的開始,或者如果您有更多時間,請考慮嘗試本教程
< dependency >
< groupId >com.renomad</ groupId >
< artifactId >minum</ artifactId >
< version >8.0.5</ version >
</ dependency >編譯尺寸:200千元。
生產代碼線(包括所需的依賴項)
| 很小 | Javalin | 春季引導 |
|---|---|---|
| 5,335 | 141,048 | 1,085,405 |
請參閱詳細信息
請參閱框架性能比較
有關使用此框架的示例項目,請參見以下鏈接。
最小的可能
該項目可以看到可以製定的最小可能的應用程序很有價值。這可能是在新項目中使用Minum的好起點。
例子
這是一個很好的例子,可以看到具有各種功能的基本項目。它顯示了微小框架的許多典型用例。
紀念項目
這是一個家庭樹項目。它證明了該框架旨在培養的方法。
實例化新數據庫:
var db = new Db <>( foosDirectory , context , new Foo ());將新對象添加到數據庫中:
var foo = new Foo ( 0L , 42 , "blue" );
db . write ( foo ); 在數據庫中更新對象:
foo . setColor ( "orange" );
db . write ( foo ); 從數據庫中刪除:
db . delete ( foo ); 編寫日誌語句:
logger . logDebug (() -> "hello" );解析HTML文檔:
List < HtmlParseNode > results = new HtmlParser (). parse ( "<p></p>" );在解析圖中搜索元素:
HtmlParseNode node ;
List < HtmlParseNode > results = node . search ( TagName . P , Map . of ());創建一個新的Web處理程序(可以處理HTTP請求並返迴響應的函數):
public Response myHandler ( Request r ) {
return Response . htmlOk ( "<p>Hi world!</p>" );
}註冊該端點:
webFramework . registerPath ( GET , "formentry" , sd :: formEntry );構建和渲染模板:
TemplateProcessor foo = TemplateProcessor . buildProcessor ( "hello {{ name }}" );
String rendered = foo . renderTemplate ( Map . of ( "name" , "world" ));從請求獲取查詢參數:
String id = r . requestLine (). queryString (). get ( "id" );從請求中獲取身體參數,作為字符串:
String personId = request . body (). asString ( "person_id" );從請求獲取路徑參數作為字符串:
Pattern requestRegex = Pattern . compile ( ".well-known/acme-challenge/(?<challengeValue>.*$)" );
final var challengeMatcher = requestRegex . matcher ( request . requestLine (). getPathDetails (). isolatedPath ());
// When the find command is run, it changes state so we can search by matching group
if (! challengeMatcher . find ()) {
return new Response ( StatusLine . StatusCode . CODE_400_BAD_REQUEST );
}
String tokenFileName = challengeMatcher . group ( "challengeValue" );從請求獲取身體參數,作為字節數組:
byte [] photoBytes = body . asBytes ( "image_uploads" );在測試過程中檢查日誌消息:
assertTrue ( logger . doesMessageExist ( "Bad path requested at readFile: ../testingreadfile.txt" ));