Akka Slick REST service template
=========================
Goal of example is to show how create reactive REST services on Lightbend stack with Akka and Slick.
Example contains complete REST service for entity interaction.
### Features:
* CRUD operations
* Entity partial updates
* CORS support
* Authentication with *JWT* tokens
* Test coverage with *ScalaTest*
* Migrations with *FlyWay*
* Ready for *Docker*
* Testing with in-memory postgres instance that launch automatically
* *HikaryCP* as connection pool
## Requirements
* JDK 8 (e.g. [http://www.oracle.com/technetwork/java/javase/downloads/index.html](http://www.oracle.com/technetwork/java/javase/downloads/index.html));
* sbt ([http://www.scala-sbt.org/release/docs/Getting-Started/Setup.html](http://www.scala-sbt.org/release/docs/Getting-Started/Setup.html));
## Development guide
This application is fully tested with Unit and IT tests.
You don't need to launch server locally for development.
My recommendation is to write a test before changes and work via TDD.
To ensure that application working properly, you should run it: `sbt test`.
### Structure
All business logic is located in `core` package, every package inside is related to some domain.
Service classes contains high level logic that related to data manipulation,
that means that service MUST NOT implement storaging and querying for the data.
For storaging there are Storage classes that always have interface with two implementation, production one and
in-memory one. That's needed to fasten tests of services and make it independent from each other.
### Code formatting
There are [Scalafmt](https://scalameta.org/scalafmt/) integrated to the project. Its a opinionated code formatter that
formats a code automatically instead of you. To use it, please run `sbt scalafmt` before commit or enable format on save
in IntelijIdea (should be available in other editors too).
### Checking code coverage
To generate code coverage report, please run: `sbt clean coverage test coverageReport`.
Then you will have HTML pages with reports in `/target/scala-2.12/scoverage-report`
### Packaging
Application packaging implemented via [sbt-native-packager](https://github.com/sbt/sbt-native-packager) plugin.
Currently in `build.sbt` enabled two types: docker and universal.
**Universal packager**
To package application as a universal app, use: `sbt universal:packageBin`.
Application zip archive will be generated in `/target/universal/` folder.
**Docker packager**
To package application as docker image, use `sbt docker:publishLocal`.
It will generate and push application image into your local docker store.
For information about publishing to external store, please, read [plugin documentation](http://www.scala-sbt.org/sbt-native-packager/formats/docker.html).
### Running
If you want to launch application locally (its not recommended) you need to start Postgres instance locally and fulfill
some env variables:
- `JDBC_URL` - url to your database
- `JDBC_USER` - database username
- `JDBC_PASSWORD` - database password
After that, just run `sbt run` and enjoy hacking. For better expirience you can use `sbt reStart` that will give you ability to
restart application without restarting of sbt.
### Deployment on production
Easiest way to deliver your application, is to do it with docker. Publish image into the store and then use
docker-compose file with structure like in `docker-compose.yml`.
## Live example
Application deployed on heroku and can be accessed by URL [http://akka-http-rest.herokuapp.com/](http://akka-http-rest.herokuapp.com/).
First request can take some time, because heroku launch up project.
You can see documentation for this example on [Apiary](http://docs.akkahttprest.apiary.io).
## Copyright
Copyright (C) 2017 Arthur Kushka.
Distributed under the MIT License.
## Contact
Wanna ask me something or stay in touch?
Follow my Twitter [@arhelmus](https://twitter.com/Arhelmus)
没有合适的资源?快使用搜索试试~ 我知道了~
akka-http-rest, 在 akka http上使用灵活REST服务编写示例.zip
共40个文件
scala:26个
conf:3个
sql:2个
需积分: 10 2 下载量 192 浏览量
2019-09-18
04:13:35
上传
评论
收藏 31KB ZIP 举报
温馨提示
akka-http-rest, 在 akka http上使用灵活REST服务编写示例 Akka平滑REST服务模板 例如展示如何使用Akka和Slick在Lightbend堆栈上创建反应性REST服务。示例包含实体交互的完整REST服务。插件功能:CRUD操作实体部分更新CORS支持使用 JWT 令牌进
资源推荐
资源详情
资源评论
收起资源包目录
akka-http-rest.zip (40个子文件)
akka-http-rest-master
.gitignore 179B
README.md 4KB
build.sbt 2KB
Procfile 66B
docker-compose.yml 440B
LICENSE 1KB
src
test
resources
application.conf 121B
scala
me
archdev
utils
InMemoryPostgresStorage.scala 1KB
http
routes
ProfileRouteTest.scala 5KB
AuthRouteTest.scala 2KB
HttpRouteTest.scala 828B
core
auth
AuthDataStorageSpec.scala 2KB
AuthServiceTest.scala 2KB
profiles
UserProfileStorageSpec.scala 3KB
UserProfileServiceTest.scala 3KB
BootIT.scala 724B
BaseServiceTest.scala 412B
main
resources
application.conf 294B
db
migration
V2__Create_auth_table.sql 150B
V1__Create_profiles_table.sql 126B
scala
me
archdev
restapi
utils
SecurityDirectives.scala 776B
db
DatabaseMigrationManager.scala 349B
DatabaseConnector.scala 564B
Config.scala 537B
MonadTransformers.scala 1KB
Boot.scala 2KB
http
routes
AuthRoute.scala 1KB
ProfileRoute.scala 2KB
HttpRoute.scala 909B
core
package.scala 936B
auth
AuthDataStorage.scala 1KB
AuthService.scala 1KB
AuthDataTable.scala 677B
profiles
UserProfileStorage.scala 1KB
UserProfileTable.scala 653B
UserProfileService.scala 859B
.scalafmt.conf 360B
.travis.yml 948B
project
plugins.sbt 277B
build.properties 18B
共 40 条
- 1
资源评论
weixin_38744207
- 粉丝: 343
- 资源: 2万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功