Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Rust Web Programming

You're reading from   Rust Web Programming A hands-on guide to developing fast and secure web apps with the Rust programming language

Arrow left icon
Product type Paperback
Published in Feb 2021
Publisher Packt
ISBN-13 9781800560819
Length 394 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Maxwell Flitton Maxwell Flitton
Author Profile Icon Maxwell Flitton
Maxwell Flitton
Arrow right icon
View More author details
Toc

Table of Contents (19) Chapters Close

Preface 1. Section 1:Setting Up the Web App Structure
2. Chapter 1: Quick Introduction to Rust FREE CHAPTER 3. Chapter 2: Designing Your Web Application in Rust 4. Section 2:Processing Data and Managing Displays
5. Chapter 3: Handling HTTP Requests 6. Chapter 4: Processing HTTP Requests 7. Chapter 5: Displaying Content in the Browser 8. Section 3:Data Persistence
9. Chapter 6: Data Persistence with PostgreSQL 10. Chapter 7: Managing User Sessions 11. Chapter 8: Building RESTful Services 12. Section 4:Testing and Deployment
13. Chapter 9: Testing Our Application Endpoints and Components 14. Chapter 10: Deploying Our Application on AWS 15. Chapter 11: Understanding Rocket Web Framework 16. Assessments 17. Other Books You May Enjoy Appendix A: Understanding the Warp Framework

Extracting data

Extracting data from the request body is fairly straightforward. All we have to do is define a struct with the attributes we want, and then pass that through as a parameter in the view function. Then, the data from the request body will be serialized to that schema. We can do this by defining the following struct in our json_serialization/to_do_item.rs file:

use serde::Deserialize;
#[derive(Deserialize)]
pub struct ToDoItem {
    pub title: String,
    pub status: String
}

Here, we have used the Deserialize macro. Now that we have this, we can start building our edit view in the views/to_do/edit.rs file. Because the view requires a lot of code, we will be breaking it down into sections. First, we need to import all of the crates that we are going to use:

use actix_web::{web, HttpResponse};
use serde_json::value::Value;
use serde_json::Map;
use super::utils::return_state;
use crate::state::read_file;
use crate::to_do:...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image