Coder Social home page Coder Social logo

phase-4-nested-resource-routing-lab's Introduction

Nested Resource Routing Lab

Learning Goals

  • Create nested routes
  • Use params in nested routes

Introduction

In this lab, we'll continue working on our Craigslist-style marketplace API, and build out some nested routes to give users easier access to our data.

User -< Item

Get the lab set up by running:

$ bundle install
$ rails db:migrate db:seed

There is seed data in place so you can test your solution out in Postman. You can also run learn test to run the tests.

Instructions

You will need to handle the requests listed below and return the appropriate JSON data in the response.

Note: watch out for Rails' DoubleRenderError as you work. The error is fairly straightforward: Rails only allows render to be called once in an action. We have seen one way to avoid this error: by using conditional code to ensure that only one render executes. A second way to avoid the error is to include an explicit return, eg: return render json: ... to keep any later render statements from executing.

Nested Items Index Route

This route should show all items for one individual user.

GET /users/:user_id/items

Response Body
-------
[
  {
    "id": 1,
    "name": "Non-stick pan",
    "description": "Sticks a bit",
    "price": 10,
    "user_id": 1
  },
  {
    "id": 1,
    "name": "Ceramic plant pots",
    "description": "Plants not included",
    "price": 31,
    "user_id": 1
  }
]

Nested Item Show Route

This route should show one item matching the :id from the URL.

GET /users/:user_id/items/:id

Response Body
-------
{
  "id": 1,
  "name": "Non-stick pan",
  "description": "Sticks a bit",
  "price": 10,
  "user_id": 1
}

Nested Item Create Route

This route should create a new item that belongs to a user.

POST /users/:user_id/items

Headers:
-------
Content-Type: application/json

Request Body:
-------
{
  "name": "Garden gnomes",
  "description": "No refunds",
  "price": 23
}

Response Body:
-------
{
  "id": 2,
  "name": "Garden gnomes",
  "description": "No refunds",
  "price": 23,
  "user_id": 1
}

Resources

phase-4-nested-resource-routing-lab's People

Contributors

ihollander avatar lizbur10 avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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.