Creating APIs with Play: a summary
In the last section, we deployed an API that responds to GET requests. Since this is a lot to take in, let's summarize how to go about API creation:
- Define appropriate routes in
/conf/routes
, using wildcards in the URL as needed. - Create Scala case classes in
/app/models
to represent the models used by the API. - Create
Write[T]
methods to write models to JSON or XML so that they can be returned by the API. - Bind the routes to controllers. If the controllers need to do more than a trivial amount a work, wrap the work in a future to avoid blocking the server.
There are many more useful components of the Play framework that you are likely to need, such as, for instance, how to use Slick to access SQL databases. We do not, unfortunately, have time to cover these in this introduction. The Play framework has extensive, well-written documentation that will fill the gaping holes in this tutorial.