Chapter 4. Defining the application’s HTTP interface

 

This chapter covers

  • Defining the URLs that the web application responds to
  • Mapping HTTP requests to Scala methods for defined URLs
  • Mapping HTTP request data to type-safe Scala objects
  • Validating HTTP form data
  • Returning a response to the HTTP client

This chapter is all about controllers, at least from an architectural perspective. From a more practical point of view, this chapter is about your application’s URLs and the data that the application receives and sends over HTTP.

In this chapter, we’re going to talk about designing and building a web-based product catalog for various kinds of paperclips that allows you to view and edit information about the many different kinds of paperclips you might find in a paperclip manufacturer’s warehouse.

4.1. Designing your application’s URL scheme

If you were to ask yourself how you designed the URL scheme for the last web application you built, your answer would probably be that you didn’t. Normally, you build a web application, and its pages turn out to have certain URLs; the application works, and you don’t think about it. This is an entirely reasonable approach, particularly when you consider that many web frameworks don’t give you much choice in the matter.

4.2. Controllers—the interface between HTTP and Scala

4.3. Routing HTTP requests to controller actions

4.4. Binding HTTP data to Scala objects

4.5. Generating HTTP calls for actions with reverse routing

4.6. Generating a response

4.7. Summary