Adding dependencies

We actually need not only the serde crate but also the serde_derive crate. Both crates help with the serialization struct in various serialization formats. Add all three crates to the dependencies list in Cargo.toml:

serde = "1.0"
serde_derive = "1.0"
toml = "0.4"

The full list of imports in the main.rs file contains the following:

use clap::{crate_authors, crate_description, crate_name, crate_version, Arg, App};
use dotenv::dotenv;
use hyper::{Body, Response, Server};
use hyper::rt::Future;
use hyper::service::service_fn_ok;
use log::{debug, info, trace, warn};
use serde_derive::Deserialize;
use std::env;
use std::io::{self, Read};
use std::fs::File;
use std::net::SocketAddr;

As you can see, we haven't imported the serde crate here. We won't use it directly in the code because it's necessary to use the serde_derive crate instead. We have imported all macros from the serde_derive crate, because the serde crate contains the Serialize and Deserialize traits and serde_derive helps us to derive these for our structs.

Microservices often need to serialize and deserialize data when interacting with the client. We will cover this topic in the next chapter.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.189.178.237