- Overview
- Transcript
1.3 Installing Rails API
In this lesson we'll install Rails API and bootstrap the initial project. You'll also learn about the main differences between regular Rails and Rails API.
1.Introduction3 lessons, 12:00
1.1Introduction02:07
1.2Model Our Business Data05:37
1.3Installing Rails API04:16
2.Building the API10 lessons, 1:53:48
2.1Tables12:55
2.2Orders11:27
2.3Adding Items to Orders14:45
2.4Payments and Receipts11:05
2.5Providing Statistics08:46
2.6A Refactoring Opportunity13:34
2.7Pagination06:15
2.8Email12:03
2.9Active Model Serializers08:51
2.10Documenting Your API14:07
3.Conclusion1 lesson, 01:08
3.1Final Review01:08
1.3 Installing Rails API
Now that we have a visual perspective on how we're going to approach our data model we can jump into the code, but before I start installing things I wanna warn you about something. So let's just go to the browser and search for Rails API, if you do that you will go straight to the Rails API project. If you check here on GitHub, you will see that the latest commits for this gem have been on June 2015. It's been quite a long time since we had updates to Rails API. Even though we're gonna use this gem right away in the course, you should know that by the time that Rails 5 comes out, maybe around Christmas of 2015, Rails API will be merged into regular rails. As you can see by looking at the README, you'll see that Rails API has been merged into rails. And so the only way to test this out, at least at this point in time, is to use this outdated gem. Until Rails 5 comes out we'll use this one. So in the original installation notes you need to type in gem install rails-api. Now pay attention, as in with Rails 5 you will type in just the regular rails version. So let's type in rails-api because that's the one we have right now. We're gonna wait a little bit until the gem is installed and right after we're going to bootstrap our rails application. Okay. After doing this, you will need to type in the same command as with creating a new rails project. You would type in rails new and then the name of the app. For this specific case I'll call it gemstaurant, as in a ruby gem that handles restaurants. Now notice as we're gonna have to type in rails-api. This is the binary that comes with the rails api gem. On a side note, if you are going to use Rails 5 already, you just type in rails new gemstaurant, and then --api at the end. This is the new upcoming feature of Rails 5. For now, we're gonna stick to rails-api new, and then gemstaurant. You will most likely recognize the pattern of the folder structure as well as the set of operations that go inside this new installation, the bootstrapping process. You'll be most likely the very same, but with some minor changes. So let's enter the gemstaurant folder and let's just go into the editor, and look at what we have. It looks pretty much like a standard rails app but if we take a close look, where's our fuse folder? Well there isn't any. We'll only focus on models, mailers and controllers. Pay attention as you see that application controller now inherits from action control double colon API. This API base class is different from the previous one in rails in the way that it just doesn't load as many stuff as the regular rails controller. As far as models go, and configuration of the database, and migrations, all of that good stuff it's still there, testing and everything. In fact, if you take a look at the test folder everything's in there, just like regular rails. So if you're used to bootstrapping a regular rails application this should be pretty familiar to you. For now I just wanted to highlight the major differences between bootstrapping a regular rails app and an API application. Remember, at the current time, it is rails-api new, and for Rails 5 it'll just be regular rails new with --api. In the next lesson, we'll start with bootstrapping our application with our first scaffold. We'll see you soon.