Tim

Rust

How to scrape websites with Rust: basic example

In this tutorial, we are going to learn how to scrape websites with Rust. This tutorial will give you a basic idea of how to get information from a website using Rust. We are just going to scrape a single web page. Following links on the page and dealing with javascript is beyond the scope of this tutorial. My GitHub repository containing the completed project can be found here: https://github.com/tmsdev82/rust-webscrape-tutorial. Contents1 What is web scraping?2 Prerequisites3 Set up the web scrape with Rust project4 Downloading HTML4.1 Configure the HTTP client object4.2 Use the client to download a page5 Scrape useful…

Docker image for Rust backend: learn how to

In this tutorial, we will learn how to create a Docker image for a Rust backend. We are going to write a small REST API program with the warp crate. Then we will write a Docker file to build a lean Docker image for it. Creating a Docker image for our applications enables us to more easily distribute and deploy our applications, with the certainty they will run as designed. Check out the full project on my GitHub: https://github.com/tmsdev82/rust-warp-docker-tutorial. Prerequisites To be able to follow along with the tutorial some of the following is useful: Rust installed Installation of Docker…

Rust Postgres

PostgreSQL database with Rust: basic how to

In this tutorial, we will learn how to connect to and manage a PostgreSQL database using the Rust programming language. A database is often an important component for any data-based backend system. For example, the Rust REST API project we made a while ago could really use a database connection implementation: How to implement a Rust REST API with warp. We will look at the basics of how to: The example code repository can be found on my GitHub: here. Prerequisites Some Rust programming knowledge is required to follow this tutorial. Docker installed. For some basic information on docker please…

Rust

How to build a REST API server with Rust and warp

In this tutorial, we are going to build a simple Rust REST API using the warp crate. We will learn how to handle simple create, read, update, and delete operations on an in-memory “database”. This tutorial has some similarities with an earlier tutorial that was also using warp. The full code example for this tutorial can be found on my GitHub: here. I also have an article explaining how to implement authentication with warp and JSON Web Tokens: JWT security for a Rust REST API: how to. If you are interested in using WebSockets with warp give it a read:…

How to connect to a Azure Kubernetes Service

This article is about how to connect to a Azure Kubernetes Service (AKS) cluster. We will look at the steps from installing the required tools to logging in to Azure using the terminal to exploring the AKS cluster to get information using a few simple command line commands. This article is aimed at Linux based systems. Prerequisites Please have an Azure account ready to follow along with. We also need to be able to access this account from the system we run the commands from. We are also assuming that there is an existing AKS cluster we want to connect…

What is Docker and why is it used: quick primer

This article is a quick primer on Docker for those who have heard of it but have never actually worked with it. Even if you have some experience working with it, this article will provide you with tips or context that will help understand Docker. But also how to use it effectively. Why use Docker In short, Docker makes application development, packaging, and deployment easier. But, why do we need these things to be easier as developers? First, let’s look at some problems that might occur in typical environment without Docker. Applications and their dependencies Each application we develop has…

How to use JWT with Rust: learn the basics here

In this tutorial, we will learn how to use JSON Web Tokens (JWT) with the Rust programming language. We will go over the basics of JWT, the structure of a JWT, how to encode and decode a JWT. After reading this tutorial you will have a good fundamental understanding of how to use JSON Web Tokens. We will use the jsonwebtoken crate for this article. The full code example for this tutorial can be found on my GitHub: here. What is a JWT Before getting into the code, let’s first look at what a JSON Web Token is. Furthermore, why…

How to make backend configurable: crypto arbitrage part 4

We are going to learn how to make our Rust backend configurable using a YAML file. This is part 4 in a series where we build a dashboard displaying crypto triangle arbitrage information. Specifically, we are going to make configurable what streams we subscribe to for coin market data and what triangles we calculate profit for. Other entries in the series: First, Crypto triangle arbitrage dashboard: how to, part 1 Second, Crypto triangle arbitrage: how to part 2: frontend Third, Crypto triangle arbitrage dashboard, part 3: how to add logging This article’s completed code base can be found on my…

How to swap on Uniswap V2 with Rust Web3

In this article, we will go through the steps of how to swap tokens on Uniswap V2 with Rust and Web3. Using the Rust programming language we will connect to the Ethereum (test) network and interact with Uniswap. There are multiple versions of Uniswap, but in this article, we will perform transactions with Uniswap V2. Important: We will use infura.io to get a connection to an Ethereum node for this article. Infura.io will not maintain any private keys on our behalf to sign transactions with. That means we have to sign the transactions ourselves and send a raw transaction. Instead…

How to read and write YAML in Rust with Serde

In this article, we will learn how to read and write YAML files in Rust with the Serde framework. Being able to read YAML files enables you to, for example, use YAML files as configuration files for your projects. This article will not be very in-depth, just a simple example of how to read and write YAML data from a file. The full code for this article can be found on my GitHub. Prerequisites Some understanding of Rust is required. Familiarity with YAML and its structure is also a plus. Creating the project and dependencies Let’s create the project and…