GithubHelp home page GithubHelp logo

wanderfalke / play2-mini Goto Github PK

View Code? Open in Web Editor NEW

This project forked from innovaco/play2-mini

0.0 2.0 0.0 231 KB

Play 2.0 mini project - provides REST API on top of Play2

Home Page: http://typesafe.com

Scala 78.09% Java 21.91%

play2-mini's Introduction

Play2 Mini Project

Play2 Mini Project provides REST API on top of Play2

Scala

In the global package name space:

object Global extends com.typesafe.play.mini.Setup(com.example.App)

and then in your own package:

object App extends com.typesafe.play.mini.Application {
   def route  =  {
      case GET(Path("/coco")) & QueryString(qs) =>  Action{
          val o = QueryString(qs,"foo").getOrElse("noh")
          Ok(<h1>It works!, query String {o}</h1>).as("text/html")
      }
      case GET(Path("/flowers")) =>  Action{
          Ok(<h1>It works for flowers!</h1>).as("text/html")
      }
    }
}

The API is based on the always awesome Unfiltered library.

Extending the Extractor based approach with regex or simple matching is possible too:

object App extends com.typesafe.play.mini.Application {
  def route = Routes(
    Through("/people/(.*)".r) {groups: List[String] =>
      Action{
        val id :: Nil = groups
        Ok(<h1>It works with regex!, id: {id}</h1>).as("text/html")
      }
    },
    {case GET(Path("/coco")) & QueryString(qs) => Action{ request =>
        println(request.body)
        println(play.api.Play.current)
        val result = QueryString(qs,"foo").getOrElse("noh")
        Ok(<h1>It works!, query String {result}</h1>).as("text/html") }
    },
      Through("/flowers/id/") {groups: List[String] =>
        Action{
          val id :: Nil = groups
          Ok(<h1>It works with simple startsWith! -  id: {id}</h1>).as("text/html")
        }
      },
      Through("/cars/id/") {groups: List[String] =>
        ActorAction[String](myActor, Car) {reply: String =>
          Ok(reply)
        }
      }
  )
}

for more information about extractors, regex and Routes, please see

Other than this, there are many useful utilities available at your fingertip, take a look at the official guide of Play for Scala Developers

Java

In the global package name space:

//Global.scala
object Global extends com.typesafe.play.mini.SetupJavaApplicationFor[com.example.App]

and then in your own package:

 //com/example/App.java
 package com.example;

 public class App extends Controller {
   @URL("/hello")
   public static Result index() {
       return ok("It works as text!");
   }

  @URL("/foo/*/name/*")
   public static Result index2(String foo, String name) {
       response().setContentType("/text/html");
       return ok("It works:"+ foo +" "+name);
  }
}

Other than this, there are many useful utilities available at your fingertip, take a look at Play Java Utils and Async processing with Play

See sample apps for more examples.

G8 Project templates

G8 project templates are available as well.

java:

g8 typesafehub/play-mini-java.g8

scala:

g8 typesafehub/play-mini-scala.g8

Licence

The code is licensed under Apache 2 license:

This software is licensed under the Apache 2 license, quoted below.

Copyright 2011 Typesafe (http://www.typesafe.com).

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this project except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

play2-mini's People

Contributors

jboner avatar ph2734 avatar

Watchers

 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.