DartBoot
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
@RestController
classes 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.
Getting Started
Git clone this repository, and you can modify anything you want to build your own application
Directories
bin
This is dart application start entry file's directory.main.dart
is the startup script file. Usedart bin/main.dart
to start this applicationlib
This is source code library directory. All code should be placed to herelib/core
This is dartboot core code directory. Of course, you can modify any code
lib/core/annotation
Current support annotationslib/core/bootstrap
Application context librarylib/core/builder
Source code generation builders, see more detail to source_genlib/core/database
ClickHouse client、Mysql connection pool、page requestlib/core/error
A custom error used by corelib/core/eureka
Eureka client and rest api caller like feign clientlib/core/log
A designed log system to record logs, print to console and log files alsolib/core/retry
Retry classlib/core/server
Http server core codelib/core/util
Helper classes to make code more simplelib/core/dartboot.dart
DartBootApplication class. Startup a dart boot application is very simple, just likebin/main.dart
code invoke:DartBootApplication.run()
lib/feign
Put 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;
}
logs
The log files directoryresource
A public resource directory. Config files in different profiles is in root path, and static files (like html、css files) should be in child:static
directory. Currently, only few extensions' files could be served as static files, but you can configserver.static.supportExts
in config files to change supported static files patterns
Static files
banner.txt
If you used springboot before, you would known what is a banner for springboot application. Yes, that's it. Make it nowbuild.yaml
More details to see build_runner config. Please change package name inimport
configs (total 2 positions)
import: "package:dartboot/core/builder/boot_builder.dart"
# 这里请使用pubspec.yaml中的name替换'dartboot'
pubspec.yaml
Modify basic info in this file, like name、description etc. Don't delete any exists dependencies and you can add any third packages hereREADME.md
It's me
Instructions
Follow these steps, you can run and code your own dart boot application:
- Open terminal to run command:
pub get
. Maybe you should putpub
command in dartbin
directory toPATH
. This command is get all dependence packages this application needed. - Open terminal (before is ok) to run command:
pub run build_runner watch
to listen your code change events and generate dynamic codes (which defined inboot_builder
). Now you can add a new rest controller class with@RestController
annotation and application will scan it automatic right now. - Write any rest controllers (rest api) or services code in
lib
path. 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"
}
Annotations
@Bean
|@bean
Class 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.path
is the endpoint root url path, normally it could like/abc/def
. Also the default non args constructor will be invoked before application started
Configurations
profile.active
Active profile identifier which used to discover config extend config file. For example , value isdev
, then application will loadconfig-dev.yaml
in resources directory
Note: properties in
config-[profile].yaml
will override same root key properties inconfig.yaml
app.name
Application identifier which will registered to eureka center serverserver.port
Http server bind portserver.context-path
Http server root endpoint which will append as prefix to any http request (except for static files inresource/static/
directory)eureka.zone
Eureka server url, usually it's endWiths/eureka
eureka.fetch-registry-interval-seconds
Interval seconds for eureka client to fetch all applications registered in eureka center servereureka.heartbeat-interval-seconds
Interval seconds for eureka clients send heartbeat signal to eureka center server, to keep client onlinedatabase
Mysql database or mongodb database configuration should be placed heredatabase.[mysql_id].host
Mysql server host addressdatabase.[mysql_id].port
Mysql server portdatabase.[mysql_id].db
Mysql server database namedatabase.[mysql_id].username
Mysql server connect user namedatabase.[mysql_id].password
Mysql server connect user passworddatabase.[mysql_id].min-pool-size
Mysql connection pool min keep alive sizedatabase.[mysql_id].max-pool-size
Mysql connection pool max connection size
Release notes
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.