Smart Sort Web Service
This page demonstrates a RESTful web service that receives an unsorted list of screw sizes, and returns the same list, sorted in a way that users find natural. Read more about how it works, or why I did this, or just try it out! Submit the example screw sizes (or paste in your own). The data are sent to the smart sort service via an AJAX call, and then the sorted values appear in the page.
Unsorted Screw Sizes
Sort these examples, or paste in your own...
How does it work?
This page (the client) takes a set of screw size values (including some invalid ones for illustration), shuffles them and puts them into the 'Unsorted Screw Sizes' box on the left. You can replace these with your own values if you wish. When you click Submit, the client assembles the values into a JSON object and sends them via an Ajax POST to the web service.
The web service receives that http request, unpacks the JSON into a python object. Regular expression pattern matching is used to match, parse, group and sort the data, with a different sort algorithm for each pattern. The sorted data is then put into JSON form and returned to the client (this web page). Any unmatched values are grouped separately.
This page then receives that Ajax reply, and writes the results to the Smart-Sorted Sizes box on the right. Matched values appear in green and unmatched in red, so you can see what the service did with the input data.
Sorting screw sizes was a real problem I encountered at work a couple of years ago. Although we wound up solving it in a different way, I still like the idea of a web service that uses regex pattern matching to sort complex data. It would be easy to extend the service to accommodate other kinds of data, by including a data type parameter in the service call, along with the data to be sorted.