concept single item in category elixir

appears as: single Item, single item
Phoenix in Action

This is an excerpt from Manning's book Phoenix in Action.

Table 9.1. Typical RESTful routes (view table figure)

HTTP method

Handler CRUD action

Example route

Typical purpose

GET index /items Provides a listing of Items or an overview of the Item resource
GET new /items/new Displays a form to enable a user to provide attributes to create a new Item
POST create /items Creates a new Item based on the attributes in the request payload; typically, this is hit from GET /items/new
GET show /items/:id Views a single Item based on an identifier (like ID number)
GET edit /items/:id/edit Displays a form so a user can provide attributes to edit a single Item identified by :id
PATCH or PUT update /items/:id Updates an existing Item based on the attributes in the request payload; typically, this is hit from GET /items/:id/edit
DELETE delete /items/:id Deletes an existing Item identified by :id
Listing 14.14. Testing Auction.get_item/1
defmodule AuctionTest do
  # ...

  describe "get_item/1" do
    setup do
      {:ok, item1} = Repo.insert(%Item{title: "Item 1"})
      {:ok, item2} = Repo.insert(%Item{title: "Item 2"})
      %{items: [item1, item2]}
    end

    test "returns a single Item based on id", %{items: items} do
      item = Enum.at(items, 1)
      assert item == Auction.get_item(item.id)          #1
    end
  end