Reading JSON requests
Now your web service is able to send JSON data representing the application data. However, clients cannot yet create new data by sending JSON requests; the create
action is still not implemented. This action should read the JSON data of requests to extract the information required to create a new item, effectively create the item, and return a response telling the client whether its operation succeeded.
The first step consists in defining which information is required to create a new item:
case class CreateItem(name: String, price: Double)
The equivalent Java code is as follows:
public class CreateItem { public String name; public Double price; }
The CreateItem
data type just glues together the information needed to create a new ...
Get Play Framework Essentials now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.