MIME-Type Conversion in Ten Lines of Code
If you’ve ever written a web service, you’ve probably needed to validate and convert MIME types to their file extension. For example, when a request comes into the server with an Accept header of application/javascript, we must know how to handle this MIME type and render a .js template. To tackle this problem in most languages, we would store the MIME data in a map and consult the keyspace for MIME-type conversions. This can become tedious with large datasets where we would need to convert the data by hand into a format representable within our programs. Fortunately, Elixir makes this easy for us with just a touch of metaprogramming. Head back over to your editor and let’s get to work.
Making Use of Existing ...
Get Metaprogramming Elixir 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.