Note: the -api flag tells Rails that we want to build an API-only application. Let us quickly generate a new project books-api by running rails new books-api -api -T -d postgresql. I used dbdiagram.io, a free online tool that allows you to draw an Entity-Relationship Diagram painlessly by just writing code. Your screen should display all instances of secret menu items with Peanut butter bacon cheeseburger with instance id 4.The figure above shows a simple design of our database. Your key column should already be filled out with the following from testing our create action and route earlier.Ī bacon burger with a side of peanut sauce In the key value table, update the values. We are going to tell Postman that we want to update Hash Brown McMuffin by providing its id in the request URL. Let's say we want to update our Hash Brown McMuffin instance with an entirely different secret menu time. Update action responds to HTTP Method PATCH. Update enables our API to update an existing instance of a secret menu item. This means that our create action and route have been set up correctly! On your screen, you will see our new instance of Hash Brown McMuffin. Under Value column, copy and paste the followingĪn Egg McMuffin with the hash brown right in the center Under Key column, copy and paste the following Under key column, we will enter attribute names and under value column, we will enter values for corresponding attributes. This will display a table with key and value as columns. It will display another row of options below. Right below the row that contains HTTP method, URL bar, and send button, you will see a row of tabs. We are going to create one using Postman! Remember how we created new instances of a secret menu items in our seed.rb? HOW TO TEST CREATE ACTION AND CREATE ROUTEĬreate enables API to create a new instance of our secret menu item. This means that our index action and route have been set up correctly! Each object is an instance of secret menu items. On your screen, you will see an array of objects. Index enables our API to display all instances of secret menu items in our API. To the right of the URL bar, you will see a blue send button.Ĭlick on send button after we have set up all the necessary parameters to test our API functionality. This is where we will enter the URL of our API server. To the right of our HTTP method button, you will see a gray bar with a placeholder "Enter request URL". We will be using different HTTP methods to test different actions of our API (more on that later!). If you click on downward facing arrow, you will see drop down options for other HTTP methods. When you open Postman you will see a gray bar between two buttons(GET and Send). Postman is a useful tool to test our API functionality. In your 02042720449_create_secret_menu_items.rb, copy and paste the following: name of the restaurant that offers secret menu item.We will display this information by setting the following as attributes of a secret menu item: Our API is designed to display useful information about secret menu items. STEP 4: Specify attributes and datatypes of a secret menu item Your file will have a different timestamp. NOTE:202042720449 is a timestamp that denotes the time and date I have created the migration file. To help you find these files, the file directory is included in the second line.Ī controller called secret_menu_items_controller.rb app>controllers>secret_menu_items_controller.rbĪ database migration table called 202042720449_create_secret_menu_items.rbĭb>migrate>202042720449_create_secret_menu_items.rb You will see that this command has created the following files in one swoop! This command will create a new Rails API named secret_menu_api.Įnter fullscreen mode Exit fullscreen mode In the directory of your choosing, type the following into your terminal.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |