Rust Web Programming by MAXWELL FLITTON

Rust Web Programming by MAXWELL FLITTON

Author:MAXWELL FLITTON
Language: eng
Format: epub
Publisher: Packt Publishing Pvt Ltd
Published: 2023-01-20T00:00:00+00:00


By the end of this chapter, we will have refactored our Rust application to support the principles of RESTful APIs. This means that we are going to map out the layers of our Rust application, create uniform API endpoints, log requests in our application, and cache results in the frontend.

Technical requirements

The code for this chapter can be found at https://github.com/PacktPublishing/Rust-Web-Programming-2nd-Edition/tree/main/chapter08

What are RESTful services?

REST stands for representational state transfer. It is an architectural style for our application programming interface (API) to read (GET), update (PUT), create (POST), and delete (DELETE) our users and to-do items. The goal of a RESTful approach is to increase speed/performance, reliability, and the ability to grow by reusing components that can be managed and updated without affecting the system.

You may have noticed that before Rust, slow, high-level languages seemed to be a wise choice for web development. This is because they are quicker and safer to write. This is due to the main bottleneck for the speed of processing data in web development being the network connection speed. The RESTful design aims to improve the speed by economizing the system, such as reducing API calls, as opposed to just focusing on algorithm speed. With that in mind, in this section, we will be covering the following RESTful concepts:

Layered system: This enables us to add extra functionality, such as authorization, without having to change the interface. For instance, if we must check the JSON Web Token (JWT) in every view, then this is a lot of repetitive code that is hard to maintain and is prone to error.

Uniform system: This simplifies and decouples the architecture, enabling whole parts of the application to evolve independently without clashing.

Statelessness: This ensures that our application does not directly save anything on the server. This has implications for microservices and cloud computing.

Logging: This enables us to peek into our application and see how it runs, exposing undesirable behavior even if there are no errors displayed.

Caching: This enables us to store data in the frontend to reduce the number of API calls to our backend API.

Code on demand: This is where our backend server directly runs code on the frontend.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.