A Ktor plugin that provides a concise DSL-style API for building RESTful web services based on Ktor and Jimmer
Add ktor-jimmer-rest
to your project
implementation("com.eimsound:ktor-jimmer-rest")
Use the JimmerRest plugin in your project
install(JimmerRest) {
jimmerSqlClientFactory {
inject<KSqlClient>()
}
}
Provides five types of routes (create | remove | edit | id | list
). For detailed usage, refer to
the documentation. Here, the list
is used as an example.
list<Book> {
filter {
where(
`ilike?`(table::name),
`ilike?`(table.store::name),
`between?`(table::price)
)
orderBy(table.id.desc())
}
fetcher {
by {
allScalarFields()
name()
store {
name()
website()
}
authors {
name()
firstName()
lastName()
}
}
}
}
- Inside
list<T>{}
,T
is a jimmer entity class, used to mark the context type - The filter conditions inside
filter
are the functions provided by jimmer, and we have added extensions to these functions, for example,`between?`(table::price)
is nullable and will be mapped to theprice__ge | price__le
query parameter, and for__ge | __le
, it is a special extension of`between?`
,`ilike?`
can be used with the suffixes__anywhere | __exact | __start | __end
, which correspond to different filtering functions, see the documentation for details - fetcher then continues to use the functionality of jimmer, jimmer is indeed a very powerful orm framework, and writing it is very elegant, please refer to jimmer's documentation for details