4 Implement a RESTful API

This chapter covers

  • Adding in-memory storage to our application
  • Passing around state to the route handlers
  • Reading from the in-memory storage across threads
  • Updating the in-memory storage in a thread-safe manner
  • Parsing data out of JSON and url-form bodies
  • Extracting information out of query parameters
  • Adding custom errors to our application

In the previous chapter, we started building our Q&A web service. We created our first custom types, Question and QuestionId, and started to handle error cases and return them to the user. So far, we’ve implemented the GET route for /questions and return 404 when any other path or method is requested. This chapter will expand massively on this functionality. We continue to use ...

Get Rust Web Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.