Chapter 28

Second Module Conclusion

You did it! You reached the end of the second module., and I hope you’ve learned a lot. I spent a lot of time working on it to make it a great learning experience, and I hope it was easy enough to follow.

Let’s review what we learned in this module. You will also find a few questions in the following section to confirm that you understand everything we have done so far.

28.1. What Did You Learn?

Chapter 11: Alexandria, an E-commerce Website Selling Digital Books

In the first chapter of the second module, we talked quickly about using Rails 5 API-mode and what we would be doing in the rest of the module. We also talked about testing and why we needed to write tests.

  • What’s the difference between Rails and Rails API-mode?
  • Is Alexandria “RESTful”?
  • What are some of the benefits of automated testing?

Chapter 12: Alexandria: Setup Time

In the second chapter of the module, we created the project, configured versioning with Git and setup testing. We also wrote our first test to ensure that everything was working as expected.

  • What is Git? Why did we need it?
  • What are the different types of automated tests?

Chapter 13: Adding Books and Authors

In this chapter, we worked on our models: Books, Author and Publisher (that was created in chapter 12). Defining the models with their tests and associating them with each other took most of our time.

  • Why did we define indexes in our migrations?
  • How did we handle the book cover?
  • Why didn’t we use a simple form submission system?

Chapter 14: Exposing the Books Resource

By building our first controller, we were able to offer our first resource to the world. We also learned how to write tests for controllers using request specs.

Chapter 15: Building Representations

In this chapter, we started building a set of tools to handle the representation generation. Starting with the presenters and the FieldPicker class, we were able to give more power to the client.

  • What is the FieldPicker class used for?
  • What are the advantages of letting the client pick the fields?

Chapter 16: The First Query Builder: Paginator

With the presenters ready, we built the first query builder. These builders are needed to scope down collections based on the client’s needs. The Paginator, which handles pagination, was the first one we built in this chapter.

  • Why did we start building specialized PORO classes instead of putting everything in the models/controllers/helpers?

Chapter 17: Query Builders

After the Paginator class, it was time to create the Sorter, Filter and EagerLoader classes. Those four builders contain most of the scoping needs for our clients.

  • What did we need the EagerLoader builder for?

Chapter 18: Representation Builders

With the query builders ready, it was time to finish up the representation builders. First, we needed to refactor the FieldPicker before adding the EmbedPicker. We also implemented the QueryOrchestrator class that simplified the use of all the query builders. Finally, we built the first serializer.

  • Why do we need the EmbedPicker class?
  • What is the goal of the QueryOrchestrator class?
  • Can we create different serializers?

Chapter 19: Finishing Up Our Controllers

In this chapter, we were able to finish our controllers in no time, thanks to the builders we created. We finished the books controller and added new ones for publishers and authors.

Chapter 20: Full-Text Search

To be a full-fledge e-commerce website, we need to let users find what they want using anything they give us. That’s the reason we implemented full-text search through books, publishers and authors. We also seeded a lot of data to do some tests.

  • Why did we need a Documents table for full-text search?

Chapter 21: Clients Authentication

It was finally time to start locking down our API. We don’t want anyone to use it, so we implemented client authentication using API keys.

  • Why did we want to restrict access to our API?
  • What are “realms”?
  • Are API keys safe? Why did we add a way to disable them?

Chapter 22: Users

We want people to be able to sign up for Alexandria and manage their commands. To do this, we needed to implement the concept of users.

  • Why do confirmations and password rests need to pass a callback URL?
  • What are integration tests?

Chapter 23: User Authentication and Authorization

With users ready, we needed to ensure that they are who they pretend to be and that they are authorized to perform something.

  • What are access tokens used for? How?
  • What are policies?

Chapter 24: Selling Books

Alexandria wouldn’t be a real e-commerce platform if we didn’t sell anything. In this chapter, we added a price to the books and implemented Stripe to handle payments.

  • Why do we store money as cents in the database?
  • What did we use the vcr gem for?

Chapter 25: Compression, Caching, CORS, Versioning

To optimize and improve Alexandria, we enabled compression and implemented some caching. We also added CORS support for our future JavaScript clients and talked about versioning.

  • Is compression useful? Why?
  • Does caching really help? Why?
  • Why did we need CORS support for?

Chapter 26: Writing Documentation

This chapter was all about writing, or generating. We talked about different tools that can be used to provide documentation to the developers using your API.

Chapter 27: Deployment

Finally, we deployed Alexandria. Using Heroku and CircleCI, we made the deployment flow smooth and safe.

  • What are the benefits of using continuous integration?
  • Why do we want the tests to be run every time we push something to GitHub?

28.2. Conclusion

That was a long module, and hopefully full of useful knowledge. We built a complete web API using Rails 5 API-mode and brought it all the way to being live. While that was a long road, we aren’t done with Alexandria just yet.

In the next module, we will be talking about REST and why Alexandria is not RESTful. We will fix some parts of Alexandria to make it better and turn it into an hypermedia API. We will also talk more about web standards and the future of web APIs.