A more simple framework to build a dart server side application, just like spring boot application in java
Features:
- Simple configuration to startup by using config[-profile].yaml
- Auto scan
@RestControllerclasses which are rest api endpoints - Write rest controllers just like springboot rest controller by use multi annotations
- Use eureka to observe and communicate to micro services
- Use mysql connection pool to keep mysql clients
- Also integrated with ClickHouse by rest api
- A designed log system to capture all logs and synchronize to files
Besides,I will continue to enrich this framework to support more and more features like in spring boot.
Git clone this repository, and you can modify anything you want to build your own application
binThis is dart application start entry file's directory.main.dartis the startup script file. Usedart bin/main.dartto start this applicationlibThis is source code library directory. All code should be placed to herelib/coreThis is dartboot core code directory. Of course, you can modify any code
lib/core/annotationCurrent support annotationslib/core/bootstrapApplication context librarylib/core/builderSource code generation builders, see more detail to source_genlib/core/databaseClickHouse client、Mysql connection pool、page requestlib/core/errorA custom error used by corelib/core/eurekaEureka client and rest api caller like feign clientlib/core/logA designed log system to record logs, print to console and log files alsolib/core/retryRetry classlib/core/serverHttp server core codelib/core/utilHelper classes to make code more simplelib/core/dartboot.dartDartBootApplication class. Startup a dart boot application is very simple, just likebin/main.dartcode invoke:DartBootApplication.run()
lib/feignPut feign clients (which used to call other micro services) to here refer to example code
import 'package:dartboot/core/eureka/eureka.dart';
/// User服务的FeignClient
class UserFeignClient {
static EurekaRestClient _client =
EurekaRestClient('user', rootPath: '/api-user');
static EurekaRestClient get client => _client;
}logsThe log files directoryresourceA public resource directory. Config files in different profiles is in root path, and static files (like html、css files) should be in child:staticdirectory. Currently, only few extensions' files could be served as static files, but you can configserver.static.supportExtsin config files to change supported static files patterns
Static files
banner.txtIf you used springboot before, you would known what is a banner for springboot application. Yes, that's it. Make it nowbuild.yamlMore details to see build_runner config. Please change package name inimportconfigs (total 2 positions)
import: "package:dartboot/core/builder/boot_builder.dart"# 这里请使用pubspec.yaml中的name替换'dartboot'
pubspec.yamlModify basic info in this file, like name、description etc. Don't delete any exists dependencies and you can add any third packages hereREADME.mdIt's me
Follow these steps, you can run and code your own dart boot application:
- Open terminal to run command:
pub get. Maybe you should putpubcommand in dartbindirectory toPATH. This command is get all dependence packages this application needed. - Open terminal (before is ok) to run command:
pub run build_runner watchto listen your code change events and generate dynamic codes (which defined inboot_builder). Now you can add a new rest controller class with@RestControllerannotation and application will scan it automatic right now. - Write any rest controllers (rest api) or services code in
libpath. Add any directory if you want. - When code already, next is to run application to test. Open a new terminal to run command:
dart bin/main.dart, and you will seeApplication startup completed.in terminal outputs which means application startup success. - Open a restful api client or browser to invoke your rest api like in example:
http://localhost:8700/dartboot/api/v1/example01?test=heello, and you will see outputs:
{
"a": "Example 01 response: heello"
}@Bean|@beanClass will be scanned to register into application context and the default non args constructor will be invoked before application started@RestController([path])A api endpoint class. All rest api will entry to these classes which annotated with this.pathis the endpoint root url path, normally it could like/abc/def. Also the default non args constructor will be invoked before application started
profile.activeActive profile identifier which used to discover config extend config file. For example , value isdev, then application will loadconfig-dev.yamlin resources directory
Note: properties in
config-[profile].yamlwill override same root key properties inconfig.yaml
app.nameApplication identifier which will registered to eureka center serverserver.portHttp server bind portserver.context-pathHttp server root endpoint which will append as prefix to any http request (except for static files inresource/static/directory)eureka.zoneEureka server url, usually it's endWiths/eurekaeureka.fetch-registry-interval-secondsInterval seconds for eureka client to fetch all applications registered in eureka center servereureka.heartbeat-interval-secondsInterval seconds for eureka clients send heartbeat signal to eureka center server, to keep client onlinedatabaseMysql database or mongodb database configuration should be placed heredatabase.[mysql_id].hostMysql server host addressdatabase.[mysql_id].portMysql server portdatabase.[mysql_id].dbMysql server database namedatabase.[mysql_id].usernameMysql server connect user namedatabase.[mysql_id].passwordMysql server connect user passworddatabase.[mysql_id].min-pool-sizeMysql connection pool min keep alive sizedatabase.[mysql_id].max-pool-sizeMysql connection pool max connection size
This project is still in development. Contact me or submit issues if you have any questions or meet any bug.
Open source to make code world better.