Coder Social home page Coder Social logo

phase-3-sinatra-with-active-record-post-patch-delete-lab's Introduction

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

phase-3-sinatra-with-active-record-post-patch-delete-lab's People

Contributors

ihollander avatar graciemcguire avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.