Yeah, so like every single API would have its own sort of format, and, you know, as you added more APIs, it was more and more difficult to debug what was actually going on. So the next thing for me that I saw that, like, was really, really impressive was when I first came across Ruby on Rails and REST in, I think it was around 2012. It was really impressive, because for the first time ever, I could see Rails in which your code generates your database, and then your database generates your code back and your API.
So what I mean by that, like, with Rails what you would start with is by defining a migration, and you say, you know, I'm creating this sort of table and these are the fields that are in it. And based on that, your database would be completely up-to-date, and it would even check and say, okay, this field was missing since the last time this migration, you know, your migrations ran, it'll create, you know, columns and stuff like that. But then, and this is where the magic of Rails really came in, when your Rails server actually started, it would read back from your database, and it would generate all the fields, all the methods to get those fields, all your setters and getters, based on the actual fields in your database. And your API also would respond based on those fields. And I think for the first time, once again, Rails kind of led you to believe that your code and your database are a single unit, right?
Your tests were expected to cover the database, Rails famously, you know, in unit tests, it actually loads up data from the database and you make assertions against that, as opposed to all this mocking and stuff like that. The conventional wisdom over there being that, you know, that you want to mock stuff that's outside of your service, but your database is part of your service. And I think this tight coupling was really fantastic. And for someone who was new, Rails was magic. And I think Rails is magic. And I think that's both the best and the worst part about it. With a simple scaffolding, you get a working API, you get a working server, and you get a working database. And this relies on a lot of meta programming magic from Ruby. Ask any Ruby programmer and they'll tell you that Rails is fantastic when things are working. There's no faster way to get anything done. But when things aren't working, you have to go through so many layers of magic in order to debug what's actually going on. And debugging Rails tends to be a little bit difficult. There's just so many of these magic layers that Rails sort of adds. But with every layer that you add, you're just adding that much more complexity between your API and your database.
But at least one thing that Rails did make very, very popular was REST, and it made these APIs at least very easy to reason about. So in REST, or at least the Rails flavor of REST, every single API presented itself as a CRUD. That's a create, read, update or delete operation on some resource. And quite often, or almost always, well, no, that's not true. Quite often these resources had one is to one database entities. So as a result, you as a programmer could just make a few changes and you'd have an API as well as a database. Both of which are in sync with each other, tied together through some magic Rails glue. And I believe this REST made the question of where an API endpoint was more predictable, but it didn't necessarily make the what of the API more predictable or easier to use. So what I mean by that is that if you wanted to fetch like a particular resource, you could pretty easily guess the endpoint where that API would be.
Comments