Skip to content

nicholasgalante/phase-3-sinatra-with-active-record-post-patch-delete-lab

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sinatra with Active Record: POST/PATCH/DELETE Requests Lab

Learning Goals

  • Handle non-GET requests in a controller
  • Access data in the request body with the params hash
  • Perform CRUD actions with Active Record from the controller

Setup

In this application, we'll continue working on our JSON API for the bakeries domain. As a reminder, here's what the ERD for these tables looks like:

Bakeries ERD

To set up the application, run these commands:

$ bundle install
$ bundle exec rake db:migrate db:seed

You can run the app and explore your API in the Postman by using the custom Rake task:

$ bundle exec rake server

Instructions

This is a test-driven lab, so run the tests to get started! This lab builds on the other lessons from this sections, so some of the tests are already passing; the associations between the models have been built out already, so a good place to start might be by working on adding routes to the ApplicationController for the different endpoints described in the test spec.

You should also test your routes using Postman as you go in order to get a sense of how to send data to and receive data from the server.

Routes

Define routes that do the following:

POST /baked_goods: creates a new baked good in the database, and returns data for the newly created baked good as JSON. The request will receive an object like this as params:

{
  "name": "Lemon Poppyseed Muffin",
  "price": 3,
  "bakery_id": 1
}

PATCH /bakeries/:id: updates the name of the bakery in the database, and returns data for the updated bakery as JSON. The request will receive an object like this as params:

{
  "name": "Northwestside Bakery"
}

DELETE /baked_goods/:id: deletes the baked_good from the database.

Resources

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 100.0%