September 2018
Intermediate to advanced
398 pages
9h 43m
English
To initialize the user interface, we need to get all of the products from the database—including the cart for the user, if there are any—through the web service API and add it to the layout. The code for this looks like the following:
private def initUI(origin: UndefOr[String]) = {
$.get(url = s"$origin/v1/products", dataType = "text")
.done((answers: String) => {
val products = decode[Seq[Product]](answers)
products.right.map { seq =>
seq.foreach(p =>
$("#products").append(ProductDiv(p).content)
)
initCartUI(origin, seq)
}
})
.fail((xhr: JQueryXHR, textStatus: String, textError: String) =>
println(s"call failed: $textStatus with status code: ${xhr.status} $textError")
)
}
It will come as no surprise that ...
Read now
Unlock full access