Index pages

The last thing we need is an index page. It's considered good form to return some information about a microservice when requested, but you may hide it for security reasons.

Our index page is a simple string with HTML content inside:

const INDEX: &'static str = r#"
<!doctype html>
<html>
<head>
<title>Rust Microservice</title>
</head>
<body>
<h3>Rust Microservice</h3>
</body>
</html>
"#;

This is a constant value that can't be modified. Рay attention to the start of the string, r#", if you haven't used it before. This is a kind of multiline string in Rust that has to end with "#.

Now you can compile the code and view the pages with a browser. I opened Developer Tools to show the status codes of the requests:

If you try to get a nonexistent resource, you'll get a 404 status code, which we set with the StatusCode::NOT_FOUND constant: