Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

4. Implementing REST > Responding to the REST Request

Responding to the REST Request

When the user sends a POST request to the web server, that is the key to create a new airport record. The handler needs to find the airport name and other information from the POST content with yaws_api:postvar/2, and then should create a new airport with airport:create_airport/5. Example 4-12 takes the airport name and other information, creates an airport record, and inserts it into the Mnesia database. The nice thing about Mnesia is that if it is set up correctly, data will automatically be replicated across a cluster.

Normally, when responding to a HTTP request, we return a status of 200 OK. However, here we are creating a new resource, so returning a status of 201 Created makes sense. The body could be blank or contain any relevant information such as the name and ID of the airport. In this case we return the JSON that was sent by the browser, as the ExtJS framework expects that.


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint