liveBook · Manning

Web service

As explained in Rust Servers, Services, and Apps

A web service is a software service that exposes functionality for network clients through web communication protocols.

A web service exposes application functionality to network clients through HTTP APIs. Serving JSON at an API path is a starting point: unlike serving a static HTML page, the server is returning data for a client to use. A useful first implementation handles GET requests and returns JSON, though a fuller service needs more than GET alone. section 2.0 section 2.3.5

Build the service in stages. First, a small Rust HTTP server makes TCP and HTTP request handling visible without a framework. Next, Actix Web supplies the structure for REST APIs backed by a thread-safe in-memory store. A database-backed iteration adds routes, a model, application state, an injected SQLx connection pool, and unit tests before completing the handlers. section 2.0 section 3.0 section 4.3

A course service and its client

A tutor-facing service exposes RESTful APIs for course data stored in Postgres; a separate server-rendered web app consumes the backend APIs. For a tutor list, the frontend makes a GET request, deserializes the JSON response into a typed Rust value, and renders it. Calling the service rather than querying Postgres again avoids duplicating database access logic and placing database credentials in both applications. section 1.3.1 section 7.7

#[derive(Serialize, Deserialize, Debug)]
pub struct Tutor {
    pub tutor_id: i32,
    pub tutor_name: String,
    pub tutor_pic_url: String,
    pub tutor_profile: String,
}

The Tutor struct shows the typed shape expected by the frontend when it deserializes a web-service JSON response. section 7.7

How Rust Servers, Services, and Apps covers it

How deep it goes
Builds from a limited GET-only HTTP implementation toward REST handlers, database state, and tests; the initial server is not production-ready.
Examples
Uses a JSON shipping-orders endpoint and a tutor API consumed by a server-rendered tutor-list page.
What it assumes
Assumes familiarity with Rust programming while teaching TCP and HTTP server construction before introducing Actix service structure.
What you can do after
Build it from scratch as a limited HTTP/JSON server, then apply Actix Web and SQLx to a tested database-backed REST service.
How it connects
Connects REST APIs with HTTP, JSON, application state, relational databases, unit testing, and server-rendered web applications.

Also explained in

Compare how 6 books explain web service →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Rust Servers, Services, and Apps. The section links point to the parts of the book it draws on.