Boston Code Camp 22: Solving an HTTP Problem with Promises

by Larry Spencer Saturday, November 22, 2014 6:11 AM
Here is the second Plunk from my talk at Boston Code Camp 22 on Mastering JavaScript Promises.

It demonstrates how to use Promises to solve a common problem with web sites that HTTP POST an addition to a list, and then expect an immediate HTTP GET of the entire list to include the newly posted record. The problem is that the POST may not have completed by the time the GET does, even though the POST was issued first.

The problem is solved through a JavaScript object that decorates the underlying Web API object. The decorator keeps track of POSTs whose Promises have not resolved yet, and adds them to the results of GET as necessary. Also, when a Promise is finally resolved, the decorator adds the ID (supplied in the return value of the resolution) to the POSTed object, for the benefit of any lists that may be holding it.

See the and JavaScript files in the Plunk for details.

Tags: , ,

All | ASP.NET MVC | General | Talks

About the Author

Larry Spencer

Larry Spencer develops software with the Microsoft .NET Framework for ScerIS, a document-management company in Sudbury, MA.