Last active
August 29, 2015 14:00
-
-
Save isterin/11272151 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
abstract class BaseResource | |
extends ScalatraServlet with FutureSupport with JacksonJsonSupport with SwaggerSupport with Imports { | |
override protected val applicationName = Some("messaging-api") | |
protected def applicationDescription = "Messaging Services API" | |
protected implicit val defaultTimeout = Timeout(5 seconds) | |
override val jsonpCallbackParameterNames: Iterable[String] = Some("callback") | |
protected override def transformRequestBody(body: JValue): JValue = body.camelizeKeys | |
protected override def transformResponseBody(body: JValue): JValue = body.underscoreKeys | |
before() { | |
contentType = formats("json") | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait Imports { | |
implicit def jsonFormats = GlobalContext.jsonFormats | |
implicit def swagger = GlobalContext.swagger | |
implicit val system = GlobalContext.system | |
implicit val executor = GlobalContext.executor | |
} | |
object GlobalContext { | |
implicit def jsonFormats: Formats = DefaultFormats + new TemplateTypeSerializer + new EnumNameSerializer(DeliveryStatus) | |
implicit def swagger = new MessagingSwagger | |
implicit val system = ActorSystem() | |
implicit val executor = system.dispatcher | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ScalatraBootstrap extends LifeCycle with Logging with Imports { | |
override def destroy(context: ServletContext) { | |
system.shutdown() | |
} | |
override def init(context: ServletContext) { | |
context.mount(classOf[TestResource], "/api/test") | |
context.mount(new MessagingResourcesApp, "/api-docs/*") | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TestResource extends BaseResource with Logging { | |
val renderTemplate = (apiOperation[String]("getSomething") | |
summary "Get random data" | |
parameter pathParam[String]("name").description("Name") | |
) | |
post("/:name", operation(renderTemplate)) { | |
new AsyncResult() { | |
override val is = Future { | |
Ok(Map("a" -> "b", "name" -> params("name"))) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment