Chapter 12. RESTful Content

One of the stories from the early days of the Web is how search engines wiped out entire websites. When dynamic websites were still a new concept, developers didn’t appreciate the difference between a GET and POST request. As a result, they created pages—accessed with the GET method—that would delete pages. When search engines started crawling these sites, they could wipe out all the content.

If these web developers had followed the HTTP spec properly, this would not have happened. A GET request is supposed to cause no side effects (you know, like wiping out a site). Recently, there has been a move in web development to properly embrace representational state transfer (a.k.a. REST). This chapter describes the RESTful features in Yesod and how you can use them to create more robust web applications.

Request Methods

In many web frameworks, you write one handler function per resource. In Yesod, the default is to have a separate handler function for each request method. The two most common request methods you will deal with in creating websites are GET and POST. These are the most well supported methods in HTML, as they are the only ones supported by web forms. However, when creating RESTful APIs, the other methods are very useful.

Technically speaking, you can create whichever request methods you like, but it is strongly recommended to stick to the ones spelled out in the HTTP spec. The most common of these are the following:

GET

Used for read-only ...

Get Developing Web Apps with Haskell and Yesod, 2nd Edition 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.