Beginner Steps to Build A Rails API Quickly and Efficiently on Mac

App Creation and Setup

Open a terminal and navigate to the folder you wish to create this project in. Since we want to build an API, we can use a special flag which helps Rails know what we want and what we don’t need right away,--api. This flag helps us shave a little extra time in creation as well! Here’s the command:

rails new name_that_pooch --api --database=postgresql

Models, Controllers, Migration

Now it’s time to “generate” our model, migration file, controller, and set up routes. Let’s call our form a “guess card”, so that will be the model name in this next command, then I’ll break down the rest of what happened:

rails g resource guess_card name:text email:text breed_one:text breed_two:text breed_three:text breed_four:text breed_five:text

Conclusion

Finally, we have a working API which can accept new guess_cards, and also makes a list of all guess_cards available in an array. Our goal has been met, and I am ready to start using this API right away! Not so bad right? Rails makes it easy!

Full Stack Web Developer && Creative Thinker && Flatiron School Grad && Continuous Learner

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store