Giter Club home page Giter Club logo

lib-play's Introduction

Build Status

lib-play

Library supporting building REST APIs on play framework.

Provided Bindings

play.modules.enabled += "io.flow.play.clients.ConfigModule"
play.modules.enabled += "io.flow.play.clients.RegistryModule"
play.modules.enabled += "io.flow.play.clients.TokenModule"
play.modules.enabled += "io.flow.play.clients.UserModule"

Request Logging

To enable request logging, add the following to your play application config:

play.http.filters=io.flow.play.util.LoggingFilter

By default, all HTTP methods will be logged. To only log a specific subset of methods, add the following:

play.http.filters.logging.methods=["GET", "PUT"]

CORS

A CORS request handler is provided. To enable, add the following to your play application config (instead of LoggingFilter above):

play.http.filters=io.flow.play.util.CorsWithLoggingFilter
play.filters.cors.allowedHttpMethods = ["GET", "POST", "PUT", "DELETE", "OPTIONS"]

Global error handler for JSON APIs

This error handler capture client and server errors, always returning application/json. This handler also makes sure to log server error messages and assigns a unique error number that is returned to the user. This error number is also logged making it easy to find a particular error in the log.

Additionally, if flow environment is development, the actual contents of the exception will be returned (disabled in production to avoid leaking information).

play.http.errorHandler = "io.flow.play.util.ErrorHandler"

Traits

Anonymous Controller

-- Provides user(...) method to get an instance of the current user. -- (type: Option[User])

Identified Controller -- extends Anonymous -- requires a user to be present -- (type: User)

XXX RestController -- assumes basic authorization for the toke Default implementation uses user token through basic authorization

SQS Actor Proxy

When splitting out background processing, it became apparent that we needed to have a way to send messages from an API service to actors running in the background processing jobs service.

With minimal amount of refactoring required, we can do this by binding a proxy actor to the original actor name in the API service, which send all messages it gets over SQS to a receiver in the jobs service. The receiver will forward all messages received on its SQS queue to the original actor that now lives in the jobs service.

To use this, you need to add the ActorProxyGuiceSupport to your Actor guice module. Then you can bind your proxy sender to the original actor name, where @Named("test-actor") actorRef: ActorRef is used.

- bindActor[TestActor]("test-actor")
+ bindActorProxySender("test-actor", ReactiveActorProxySerde)

Then in your jobs service you can bind your original actor with a proxy receiver.

+ bindActor[TestActor]("test-actor")
+ bindActorProxyReceiver(
+   name = "test-actor-receiver",
+   proxiedName = "test-actor",
+   serde = ReactiveActorProxySerde
+ )

Once that is done, you can send messages as you normally would, as long as your ProxySerde passed to your sender and receiver, knows how to serialize and deserialize the messages.

class TestActorCaller @Inject() (@Named("test-actor") actor: ActorRef) extends Actor with ActorLogging {
  override def receive: Receive = {
    case Tick =>
      // the following really send the message to the proxy we have bound to "test-actor"
      actor ! ReactiveActor.Messages.Changed
  }
}


class TestActor extends Actor with ActorLogging {
  override def receive: Receive = {
    case ReactiveActor.Messages.Changed => log.info("RECEIVED TEST ACTOR CHANGED MESSAGE!")
  }
}

NOTE: The sender and receiver will use the service name and the proxied receiver actor name to create an SQS queue

Publishing a new version

go run release.go

Publishing a new snapshot for local development

edit build.sbt and append -SNAPSHOT to version
sbt +publishLocal

lib-play's People

Contributors

mbryzek avatar mikeclimbrock avatar jlogeart avatar aksharp avatar kubukoz avatar darrenmc avatar ericluria avatar grahamar avatar benwaffle avatar chrhicks avatar jpkeanu avatar paololim avatar gheine avatar rbern avatar

Watchers

James Cloos avatar  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.