GithubHelp home page GithubHelp logo

cw-junichikato / trinity Goto Github PK

View Code? Open in Web Editor NEW

This project forked from j5ik2o/trinity

0.0 2.0 0.0 6.83 MB

Trinity is a lightweight MVC framework based on Finagle

Shell 4.22% Scala 32.76% HTML 0.09% Makefile 0.87% Prolog 0.01% C 62.05%

trinity's Introduction

Trinity

Build Status

Trinity is a lightweight MVC framework based on Finagle, written in Scala.
Since May 2013

Concepts

  • Provide MVC functions not supported by Finagle.
  • Support Domain Driven-Design by non CoC(Convention over Configuration).

Features

  • You can use Actions as Controller, instead of Finagle Service.
    • URLs can be mapped to action methods, like Scalatra.
    • Otherwise, The Routing information can be outside of the Controller, like Play2.
  • You can use Template Engine (e.g. Scalatra) with Trinity.

Functions

Supported Functions

  • Routing request to action. return's type is scala.concurrent.Future
  • Finagle's Request/Response Enhance
    • Multi-part file upload
    • JSON format reponse
    • File resouce support
  • Binding to Template Engine
  • Testing
    • Unit testing
    • Integration testing
  • JRebel support

Unsupported Functions

  • Form
  • Validation
  • Persistence(e.g. RDBMS/NoSQL)

License

Apache License, Version 2.0

Setup

Build Configuration

Please add the following configuration to Build.scala.

Release Version

resolvers += "Sonatype Release Repository" at "http://oss.sonatype.org/content/repositories/releases/"

libraryDependencies +=  "org.sisioh" %% "trinity-core" % "1.0.11"

Snapshot Version

resolvers += "Sonatype Snapshot Repository" at "http://oss.sonatype.org/content/repositories/snapshots/"

libraryDependencies +=  "org.sisioh" %% "trinity-core" % "1.0.12-SNAPSHOT"

Controller code

Scalatra like controller

object ScalatraLikeControllerApplication
  extends ConsoleApplication {

  get("/hello") {
    request =>
      responseBuilder.withTextPlain("Hello World!!").toFuture
  }

  get("/json") {
    request =>
      val jValue = JObject(
        JField("name", JString("value"))
      )
      responseBuilder.withJson(jValue).toFuture
  }

  get("/user/:userId") {
    request =>
      responseBuilder.withTextPlain("userId = " + request.routeParams("userId")).toFuture
  }

  get( """/group/(.*)""".r, Seq("name")) {
    request =>
      ResponseBuilder().withTextPlain("name = " + request.routeParams("name")).toFuture
  }

  startWithAwait()

}

Play2 like controller

object PlayLikeApplicationForController extends ConsoleApplication {

  case class MainController() extends ControllerSupport {

    def helloWorld = SimpleAction {
      request =>
        responseBuilder.withTextPlain("Hello World!!").toFuture
    }

    def getUser = SimpleAction {
      request =>
        responseBuilder.withTextPlain("userId = " + request.routeParams("userId")).toFuture
    }

    def getGroup(name: String) = SimpleAction {
      request =>
        responseBuilder.withTextPlain("name = " + name).toFuture
    }
  }

  val mainController = MainController()

  override protected val routingFilter = Some(RoutingFilter.createForActions {
    implicit pathPatternParser =>
      Seq(
        Get % "/hello" -> mainController.helloWorld,
        Get % "/user/:userId" -> mainController.getUser,
        Get % ("""/group/(.*)""".r -> Seq("name")) -> {
          request =>
            mainController.getGroup(request.routeParams("name"))(request)
        }
      )
  })

  startWithAwait()

}

Build

$ sbt clean compile

Run

$ sbt run

Test

$ curl -X GET http://localhost:7070/hello
Hello!

trinity's People

Contributors

j5ik2o avatar mychangle123 avatar hase1031 avatar takc923 avatar tarugo07 avatar

Watchers

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