Routes Constraints and Namespaces
Learn how to add routes and define data format in the application.
We'll cover the following
In this lesson, we will be working on the config/routes.rb
file. Specifically, we will set the route constraints and the default response format for each request.
Create an API controller
Let’s start by isolating the API controllers under a namespace.
This is fairly simple process with Rails. First, we have to create a folder under the app/controllers
named api
. The name is important because that’s the namespace we’ll use to manage the API endpoints’ controllers. We will create this folder using the following command:
$ mkdir app/controllers/api
Now create this folder in our app by typing this command in the terminal below.
Get hands-on with 1200+ tech skills courses.