O'Reilly logo

Metaprogramming Elixir by Chris McCord

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required