Giter VIP home page Giter VIP logo

akka-http-slick-sample's Introduction

akka-http-slick-sample

This is just a sample application with akka http and slick

Build Status

Goal

Make a simple application which shows the devs how to use these great libs

Json Marshalling

Decided to use the very popular spray json marshaller

/**
  * Implicit json conversion -> Nothing to do when we complete the object
  */
trait JsonProtocol extends SprayJsonSupport with BaseJsonProtocol {
  implicit val userFormat: RootJsonFormat[User] = jsonFormat3(User)
}

Akka Http

You can find under routes, service, server the akka http implementation

// Test routes
  val routes: Route = pathPrefix("user") {
    pathEndOrSingleSlash {
      get {
        complete(repo.getAll)
      }
    }
  }
  
// Http service
trait HttpService {
  implicit lazy val system: ActorSystem = ActorSystem()
  implicit lazy val ex: ExecutionContext = system.dispatcher
  implicit lazy val materializer: ActorMaterializer = ActorMaterializer()

  lazy val userRepo: UserRepository = new UserRepository

  lazy val routes: Route = new UserRoutes(userRepo).routes
}
  
  
// Http server (needs a service) nothing special at all
trait HttpServer extends UserSampleConfig {
  implicit def system: ActorSystem

  implicit def materializer: Materializer

  implicit def ex: ExecutionContext

  def routes: Route

  Http().bindAndHandle(routes, httpHost, httpPort)
}

Slick

I highly recommend to check the slick database configuration for the right production settings (for your needs)

// Just an private accessor for the general database settings
private[persistence] object DB {

  import slick.jdbc.PostgresProfile.api._

  lazy val connectionPool = Database.forConfig("database")
}

Special

In this example you have a ready to use generic repository which is based on UUID's.

You have one database configuration (from configuration). You can replace the configuration with a simple test configuration (see the test folder)

You don't have to influence your code cause of in memory tests!

akka-http-slick-sample's People

Contributors

freshwood avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.