The railway API
Now that we have a working knowledge of what an API is, let's turn to something more concrete.
Before we show you the code, allow us to stress that this code is not production-ready, as that would have been too long and needlessly complex for a book's chapter. However, this code does its job and does it well, and it will allow you to learn quite a lot if you decide to study it, evolve it, and improve it. We will leave suggestions on how to do so at the end of this chapter.
We have a database with some entities that model a railway. We want to allow an external system to perform CRUD operations on the database, so we are going to write an API to serve as the interface to it.
CRUD stands for Create, Read, Update, and Delete. These are the four basic database operations. Many HTTP services also model CRUD operations through REST or REST-like APIs.
Let's start by taking a look at the project files, so you will have an idea of...