39: Rust For Better Elm - JSToElm
All Episodes

39: Rust For Better Elm

I have, for a long time, wanted to stretch my functional type safe ways into other areas of programing, to better round out my skills. And I waffled between backend languages quite a bit. If you follow us on twitter, you likely remember questions about which language would you dive into? More Haskell ? Maybe something with JVM like Scala, or Elixir with the Phoenix framework? Possibly Rust? The goal here is to explore Rust in the realm of building API's with it, and see if it's something that I like, that I could be productive in? Rust also has a **lot** of traction in web assembly, and an all around pretty great community. So let's dive in.

Rust Up?

  • The goal: can I get a server up and running with a simple endpoint that returns hello world, and better still, read params and get “Hello whatever” back?

  • Chose Rocket for quick up and running, paired with Diesel (from the developer that built active record!)

  • Seems like such a versatile language,

  • Stability and Tooling!! cargo is sweet and rustup makes install and project management pretty straight forward.

  • Questions around deployment ??

    • I like aws lambda, but I’m not feeling super confident of my backend JS without the warm blanket of a type system. Meow Notes’ backend is all JS, and as we refactor it into Elm, I can’t help but think, what runtime errors are lurking in the backend ?

    • With that, I don’t really want to be in the sysAdmin role. I want single command deployment, and don’t want to be responsible for the server up keep anymore. I don’t want to have to deal with proxy’s and configs. Blarf!

      NOPE

    • I’ve used docker in the past, and once it’s all set up, it’s pretty straight forward, easy peasy. IDK

    • Imgur

Rocket

Forword

Rocket’s design is centered around three core philosophies:

  • Function declaration and parameter types should contain all the necessary information to validate and process a request.This immediately prohibits APIs where request state is retrieved from a global context. As a result, request handling is self-contained in Rocket: handlers are regular functions with regular arguments.
  • All request handling information should be typed. Because the web and HTTP are themselves untyped (or stringly typed, as some call it), this means that something or someone has to convert strings to native types. Rocket does this for you with zero programming overhead.
  • Decisions should not be forced. Templates, serialization, sessions, and just about everything else are all pluggable, optional components. While Rocket has official support and libraries for each of these, they are completely optional and swappable.
  • Made up of Route Attributes and Route Handlers

    • Route Attributes are micros
    • Route Handlers are functions
    • NO global request.user object. mmm, that should be interesting?

Picks

Resources

Follow

Published 7 Jun 2018

A show about learning Elm, Functional Programing, and generally leveling up as a JS developer.
JavaScript To Elm on Twitter