Implementing HTTP Basic authentication with Spray

I’ve been working with Spray for almost a year now and have been thinking of blogging about some of the things I’ve found out during that time. After answering this question on StackOverflow I realized I had most of a blog post there, so here’s my attempt at explaining how to make HTTP Basic authentication work with Spray. When implementing authentication for a REST API, I first came upon the Authentication and Authorization page on the Spray wiki.