rust

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

Binance API crypto transaction with Rust: how to

In this article, we are going to learn how to do a buy transaction of crypto with the Binance API. As usual, we will be using the rust programming language. The full project’s repository can be found on my GitHub. I also have another article related to the Binance API: Easily connect to Binance WebSocket streams with Rust Prerequisites To be able to follow this article you should have: Rust installed Some familiarity with Rust and programming against a REST API is helpful. A Binance account. Verification on your Binance account so that you can create an API key. To…

Crypto triangle arbitrage dashboard, part 3: how to add logging

Logging to a storage medium is useful for troubleshooting and analysis when any note-worthy events have occurred. In this article, we will do a quick update to the code base we created in part 1: Crypto triangle arbitrage dashboard: how to, part 1 to add logging to a file for our rust backend. We will add logging to stdout and a file making use of the log4rs crate. For details on how to use log4rs please check out my article about basic file logging with log4rs. Prerequisites Since we are updating the existing code base for the crypto triangle arbitrage…

Basic how to log to a file in Rust with log4rs

In this article, we will take look at how you can use and configure log4rs to log to a file in your Rust program. Specifically, we will look at some of the options using YAML to configure the logging. What is log4rs From the crate description: “log4rs is a highly configurable logging framework modeled after Java’s Logback and log4j libraries.” For the log4rs crate’s page click here. Why log4rs What is good about log4rs? It offers an easy way to log to a file and it is highly configurable using a YAML config file, as well as through code. However,…