3 Building a RESTful web service

 

This chapter covers

  • Getting started with Actix
  • Writing a RESTful web service

In this chapter, we will build our first real web service.

The web service will expose a set of APIs over HTTP, and will use the Representational State Transfer (REST) architectural style.

We’ll build the web service using Actix, a lightweight web framework written in Rust, which is also one of the most mature in terms of code activity, adoption and ecosystem. We will warm-up by writing introductory code in Actix to understand its foundational concepts and structure. Later, we will design and build a set of REST APIs using an in-memory data store that is thread-safe.

The complete code for this chapter can be found at https://github.com/peshwar9/rust-servers-services-apps.

Let’s get started.

Why Actix?

This book is about developing high performance web services and applications in Rust. The web frameworks considered while writing this book were Actix, Rocket, Warp and Tide. While Warp and Tide are relatively newer, Actix and Rocket lead the pack in terms of adoption and level of activity. Actix was chosen over Rocket as Rocket does not yet have native async support, and async support is a key factor to improve performance in I/O-heavy workloads (such as web service apis) at scale.

3.1 Getting started with Actix

In this book, you are going to build a digital storefront aimed at tutors.

3.1.1 Writing the first REST API

3.1.2 Understanding Actix concepts

3.2 Building web APIs with REST

3.2.1 Define project scope and structure

3.2.2: Define and manage application state

3.2.3: Defining the data model

3.2.4: Post a course

3.2.5: Get all courses for a tutor

3.2.6: Get details of a single course

3.3 Summary

sitemap