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.
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.
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.
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.
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.
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.
FieldPicker
class used for?
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.
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.
EagerLoader
builder for?
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.
EmbedPicker
class?
QueryOrchestrator
class?
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.
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.
Documents
table for full-text search?
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.
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.
With users ready, we needed to ensure that they are who they pretend to be and that they are authorized to perform something.
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.
vcr
gem for?
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.
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.
Finally, we deployed Alexandria. Using Heroku and CircleCI, we made the deployment flow smooth and safe.
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.