play2-stub
is a play framework plugin for implementing server stub without any boilerplate coding. With
routes
GET /index contollers.YourController.index
...
GET /*file jp.co.bizreach.play2stub.StubController.at(file)
application.conf
play2stub {
routes: [
{
"GET /author/~authorName/books" {
template = "author-biology"
data = "authors/:authorName.json"
}
}
]
}
Currently, play2-stub
only suppoorts Handlebars templates and depends on play2-handlebars .
Sometimes engineers collaborate with front-end engineers or UX designers in one play application. While engineers are implementing eagerly, they want server responses to test their artifacts. Today since clients become richer and richer, they really needs clear responses for both html and ajax response.
UX/UI designers/engineers also want data variation as we engineers do, to test client-side validation behaviors, for layout adjustment and so on.
- Handlebars(currently) template
- Dynamic parameter passing
- Implicit routing
-
Add a dependency in
Build.scala
orbuild.sbt
"jp.co.bizreach" %% "play2-stub" % "0.1.0"
or
"jp.co.bizreach" %% "play2-stub" % "0.2-SNAPSHOT"
with the below to refer the Maven's snapshot reository. resolvers += "Maven Central Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots"
-
Add a line in
conf/play.plugins
. Usually, you also need to add Handlebars plugin declaration.1000:jp.co.bizreach.play2handlebars.HandlebarsPlugin 2000:jp.co.bizreach.play2stub.StubPlugin
-
Add mappings to StubController routes in
routes
. Each http method needs a line.GET /*file jp.co.bizreach.play2stub.StubController.at(file)
-
Add routes in
application.conf
. The grammar is quite similar to that of Play's route. But instead of ":", use "~" for path parameters.play2stub { routes: [ { "GET /author/~authorName/books" { template = "author-biology" data = "authors/:authorName.json" } } ] }
-
Then put template files or/and json files and run your application.
-
See
src/test/play2-sample1-stub
for more routing samples.
0.2 #1 add common headers and cookie values using filter #2 enable no returning value #3
0.3 and beyond
- Some kind of collaboration with REST documentation frameworks such as Blueprint and RAML