Image for post
Image for post

We’re taking a quick breather this week from new content for an announcement. Our recently concluded Rust Web series now has a permanent spot on the advanced page of our website. You can take a look at the series page here! Here’s a quick summary of the series:

  1. Part 1: Postgres — In the first part, we learn about a basic library to enable integration with a Postgresql Database.
  2. Part 2: Diesel — Next up, we get a little more formal with our database mechanics. We use the Diesel library to provide a schema for our database application.
  3. Part 3: Rocket — In part 3, we take the next step and start making a web server! We’ll learn the basics of the Rocket server library! …


Image for post
Image for post

For a couple months now, we’ve focused on some specific libraries you can use in Rust for web development. But we shouldn’t lose sight of some other core language skills and mechanics. Whenever you write code, you should be able to show first that it works, and second that it works efficiently. If you’re going to build a larger Rust app, you should also know a bit about unit testing and benchmarking. This week, we’ll take a couple simple sorting algorithms as our examples to learn these skills.

As always, you can take a look at the code for this article on our Github Repo for the series. You can find this week’s code specifically in sorters.rs! For a more basic introduction to Rust, be sure to check out our Rust Beginners Series! …


Image for post
Image for post

A couple weeks ago we explored how to add authentication to a Rocket Rust server. This involved writing a from_request function that was very messy. You can see the original version of that function as an appendix at the bottom. But this week, we're going to try to improve that function! We'll explore functions like map and and_then in Rust. These can help us write cleaner code using similar ideas to functors and monads in Haskell.

For more details on this code, take a look at our Github Repo! For this article, you should look at rocket_auth_monads.rs. …


Image for post
Image for post

In the last few articles, we’ve been exploring the Rocket library for Rust web servers. Last time out, we tried a couple ways to add authentication to our web server. In this last Rocket-specific post, we’ll explore some ideas around frontend templating. This will make it easy for you to serve HTML content to your users!

To explore the code for this article, head over to the “rocket_template” file on our Github repo! If you’re still new to Rust, you might want to start with some simpler material. Take a look at our Rust Beginners Series as well!

Templating Basics

First, let’s understand the basics of HTML templating. When our server serves out a webpage, we return HTML to the user for the browser to render. Consider this simple index…


Image for post
Image for post

Last week we enhanced our Rocket web server. We combined our server with our Diesel schema to enable a series of basic CRUD endpoints. This week, we’ll continue this integration, but bring in some more cool Rocket features. We’ll explore two different methods of authentication. First, we’ll create a “Request Guard” to allow a form of Basic Authentication. Then we’ll also explore Rocket’s amazingly simple Cookies integration.

As always, you can explore the code for this series by heading to our Github repository. For this article specifically, you’ll want to take a look at the rocket_auth.rs file

If you’re just starting your Rust journey, feel free to check out our Beginners Series as well! …


Image for post
Image for post

We’ve now explored a couple different libraries for some production tasks in Rust. A couple weeks ago, we used Diesel to create an ORM for some database types. And then last week, we used Rocketto make a basic web server to respond to basic requests. This week, we’ll put these two ideas together! We’ll use some more advanced functionality from Rocket to make some CRUD endpoints for our database type. Take a look at the code on Github here!

If you’ve never written any Rust, you should start with the basics though! Take a look at our Rust Beginners Series!

Database State and Instances

Our first order of business is connecting to the database from our handler functions. There are some direct integrations you can check out between Rocket, Diesel, and other libraries. …


Image for post
Image for post

Welcome back to our series on building simple apps in Rust. Last week, we explored the Diesel library which gave us an ORM for database interaction. For the next few weeks, we’ll be trying out the Rocket library, which makes it quick and easy to build a web server in Rust! This is comparable to the Servant library in Haskell, which we’ve explored before.

This week, we’ll be working on the basic building blocks of using this library. The reference code for this article is available here on Github!

Rust combines some of the neat functional ideas of Haskell with some more recognizable syntax from C++. To learn more of the basics, take a look at our Rust Beginners Series! …


Image for post
Image for post

Last week on Monday Morning Haskell we took our first step into some real world tasks with Rust. We explored the simple Rust Postgres library to connect to a database and run some queries. This week we’re going to use Diesel, a library with some cool ORM capabilities. It’s a bit like the Haskell library Persistent, which you can explore more in our Real World Haskell Series.

For a more in-depth look at the code for this article, you should take a look at our Github Repository! …


Image for post
Image for post

For our next few articles, we’re going to be exploring some more advanced concepts in Rust. Specifically, we’ll be looking at parallel ideas from our Real World Haskell Series. In these first couple weeks, we’ll be exploring how to connect Rust and a Postgres database. To start, we’ll use the Rust Postgres library. This will help us create a basic database connection so we can make simple queries. You can see all the code for this article in action by looking at our RustWeb repository. Specifically, you’ll want to check out the file pg_basic.rs.

If you’re new to Rust, we have a couple beginner resources for you to start out with. You can read our Rust Beginners Series to get a basic introduction to the language. Or for some more in-depth explanations, you can watch our Rust Video Tutorial!! …


Image for post
Image for post

Next week, we’re going to change gears a bit and start some interesting projects with Rust! Towards the end of last year, we dabbled a bit with Rust and explored some of the basics of the language. In our next series of blog articles, we’re going to take a deep dive into some more advanced concepts.

We’ll explore several different Rust libraries in various topics. We’ll consider data serialization, web servers and databases, among other. We’ll build a couple small apps, and compare the results to our earlier work with Haskell.

To get ready for this series, you should brush up on your Rust basics! To help, we’ve wrapped up our Rust content into a permanent series on the Beginners page! …

About

James Bowen

Author of Monday Morning Haskell (http://mmhaskell.com)

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store