用Scala实现简单的Web和API服务器(29)

本节的完整代码如下:

用Scala实现简单的Web和API服务器

package app

import scalatags.Text.all._

object MinimalApplication extends cask.MainRoutes{

var messages = Vector(

("alice", "Hello World!"),

("bob", "I am cow, hear me moo"),

("charlie", "I weigh twice as you"),

)

var openConnections = Set.empty[cask.WsChannelActor]

defmessageList= {

frag(

for((name, msg) false, "txt"-> "Name cannot be empty")

elseif(name.length >= 10) ujson.Obj("success"-> false, "txt"-> "Name cannot be longer than 10 characters")

推荐阅读