Yes. You are right. I don't need the nightly features of Rust in this post. I just took the convenience of experimenting Rocket and Diesel with the Rust nightly compiler in my second post: https://genekuo.medium.com/creating-a-rest-api-in-rust-with-persistence-rust-rocket-and-diesel-a4117d400104. So I use the same here. We should use the stable version whenever developing in production. Thanks for pointing that out.
We will be creating a REST API in Rust, which serves resources (posts) with persistence in a postgres database.
Rocket framework will be used to setup the API and Diesel to handle persistence with a Postgres database.
We will test our Rust API and a Postgres database by running them as separate docker containers which communicate with each other to expose CRUD functionalities from our API and implement persistence with a Postgres database.
I’ve provided the source code in the
rocket-diesel branch of my Github repo.
First, we need to setup the following dependencies for our REST API project:
We will create a simple REST service providing the functions of CRUD (create, read, update, and delete) for in-memory user data. Without serialization and deserialization between JSON and Rust instances, which we will expand the source code on further articles, this example will handle only CRUD of user ids to focus on the coding of a HTTP service with Rust and relevant crates.
The sample code can be cloned from the following GitHub repository: https://github.com/genekuo/rust-microservices.git
After implementing the initial version of the microservices, we will test it by using
curl commands to see how it works.
We have decided to…
In this article, I summarises several ES6 features and a brief introduction to the concept and usage of these features with simple examples. The main goal is to provide newcomers a quick start in making use of ES6.
Prior to ES6, we can use
[[prototype]] mechanism we will discuss in this article provides behavior delegation for modelling objects in an application, such as the emulation of inheritance, polymorphism, instance construction and so on. Behavior delegation has more flexible and dynamic features than those of class-based object modelling in traditional object-oriented languages.
Many languages provides syntax which enables class-oriented software design, that is, we design parent and child classes as blueprints for objects (or instances). With traditional object-oriented language like Java, objects are instantiated…
In Kotlin, functions are the first-class citizens. They are meant to increase reusability and at the same time to reduce the possibility of unsafe programs that are often untestable and buggy. We will take a look at the functional programming features of Kotlin and understand how they help developers to write safe programs.
Many bugs come from programs executing incorrectly with the outside world, which are effects that are not easy to test and we have little control of. They are guidelines that can make our programs safer from buggy code.
Avoiding sharing mutable variables
This principle protects programs from…
In this article, we will first understand what GraphQL is when designing APIs on a software architecture. we will then get to know the concepts and the GraphQL Query operation that we can utilize to design and implement the APIs per our needs. Finally, we will build a rather simple GraphQL server based on what we have learned in this article with the help of Apollo, and test it through Apollo GraphQL Playground.
When designing network communication between client and server, REST has been one of the most popular choices in the software industry. In REST, it enables applications to…
Kubernetes is a software system that allows you to deploy and manage containerized apps. It abstracts away the underlying infrastructure to simplify development, deployment and management for both dev and ops teams. There are many benefits and components provided by the Kubernetes platform with many options about installing and setting up the Kubernetes cluster such as single-node, multiple-node and cloud-based deployments. In this article, we will focus on setting up multiple-node cluster on a laptop (such as 2.7 GHz Intel Core i5, 8G RAM should be sufficient for demonstration purpose).
In the process of setting up the Kubernetes cluster, you…