Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/modux4s/modux
Lightweight microservice server for Scala
https://github.com/modux4s/modux
akka modux sbt scala
Last synced: 29 days ago
JSON representation
Lightweight microservice server for Scala
- Host: GitHub
- URL: https://github.com/modux4s/modux
- Owner: modux4s
- License: mit
- Created: 2020-08-06T21:34:24.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-05-02T17:28:40.000Z (over 2 years ago)
- Last Synced: 2023-07-07T16:10:27.776Z (over 1 year ago)
- Topics: akka, modux, sbt, scala
- Language: Scala
- Homepage: https://modux4s.github.io/modux/
- Size: 332 KB
- Stars: 7
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Introduction
Modux is a simple and lightweight microservice server for Scala inspired on
[Lagom Framework](https://www.lagomframework.com/). The aim is to speed up development using a set of directives backed by [Scala](https://www.scala-lang.org/) and [Akka's](https://akka.io/) technologies.[![version](https://img.shields.io/badge/version-1.2.4-green.svg)](https://github.com/modux4s/modux)
[![version](https://img.shields.io/badge/scala-2.12-blue.svg)](https://github.com/modux4s/modux)
[![version](https://img.shields.io/badge/scala-2.13-blue.svg)](https://github.com/modux4s/modux)## Features
* Easy to learn and lightweight.
* Minimal configurations.
* Microservices DSL based.
* Open API 3.0 and 2.0 exporting based on Microservices definitions. You can extend documentations.
* Streaming and Kafka support.
* GraphQL support.
* Web Security through Pac4j.
* Twirl support
* Dependency Injection through Macwire.
* Websocket.
* Serialization support.
* Hot-Reloading.
* Clustering support.
* Easy production building.
* Compatible with Scala 2.12 and 2.13.# Install
1. Add to **plugin.sbt**
```scala
addSbtPlugin("io.github.joacovela16" %% "modux-plugin" % "1.2.4")
```
2. Enable plugin `enablePlugins(ModuxPlugin)` in your **build.sbt**.# For impatient
Run `sbt new modux4s/modux.g8` to build a Modux template project then `sbt ~run`.
# Quick Example
The basic project structure follows next sbt project structure.
```
root
/app
/services
/service1
/impl
Service1Def
...
/serviceN
/impl
ServiceNDef
/modules
Module1
...
ModuleN
/views
home.html.scala
userDetail.html.scala
/assets
style.css
utils.js
index.html
/conf
application.conf
logback.xml
build.sbt
```Modux defines microservices using **Service** interfaces. Lets define a basic User service.
```scala
trait UserService extends Service with SerializationSupport{implicit val userCodec: Codec[User] = codecFor[User]
def addUser(): Call[User, Unit]
def getUser(id: String): Call[Unit, User]override def serviceDef: ServiceDef =
namedAs("user-service")
.entry(
post("/user", addUser _),
get("/user/:id", getUser _)
)
}
```implemented by...
```scala
class UserServiceImpl extends UserService{def addUser(): Call[User, Unit] = extractBody{ user =>
logger.info(s"user $user created")
}def getUser(id: String): Call[Unit, User] = onCall {
if (math.random() < 0.5) {
NotFound(s"User $id not found")
} else
User(id, ZonedDateTime.now().minusYears(10))
}
}
```To use this service, it must be register through trait **ModuleX**.
```scala
class Module extends ModuleX {
override def providers: Seq[Service] = Seq(wire[UserService])
}
```Finally, add to **/conf/application.conf** under **modux.modules** the classpath of Module.
> modux.modules = [ "simple.example.Module" ]
Run "sbt ~run" and invoke "http://localhost:9000/user/test".
# Links
* [Documentation](https://modux4s.github.io/modux)
* [Examples](https://github.com/modux4s/modux-example)