title: RESTful design of many-to-many relationship to DELETE with one request
body: <p>I am creating a RESTful API to be consumed by n+ clients over HTTP. </p>
  
  <p>If I have a Users &lt;= Friendships => Friends many-to-many relationship, should I be satisfied that in order to DELETE any of a User's Friendships, I will first have to query GET friendships#index to get the ID of the friendship that I intend to DELETE, and then issue the DELETE request?</p>
  
  <pre><code>GET /friendships?user_id=123&amp;friend_id=456
  =&gt; {id:"999",user_id:"123",friend_id:"456"}
  DELETE /friendships/999
  =&gt; "Friendship deleted"
  </code></pre>
  
  <p>In order for a User to DELETE a Friendship, the application needs to have the Friendship "id" available, but in order for the User to know which Friend they are deleting, they need to see the Friend "name".</p>
  
  <p>In other words, is there a RESTful way to request the array of Friend models and their respective array of Friendship models in the same HTTP request? </p>
  
  <p>Below is my current setup:</p>
  
  <pre><code># Models
  class User &lt; ActiveRecord::Base  
    has_many :friendships, :dependent =&gt; :destroy
    has_many :friends, :through =&gt; :friendships
    # disregard inverse for now
  end
  
  class Friendship &lt; ActiveRecord::Base
    belongs_to :user
    belongs_to :friend, :class_name =&gt; "User"
    validates_uniqueness_of :user_id, :scope =&gt; :friend_id
  end
  
  
  # Tables
  create_table :users do |t|
    t.string :name
    t.timestamps
  end
  
  create_table :friendships do |t|
    t.integer :user_id, :null =&gt; false
    t.integer :friend_id, :null =&gt; false
    t.integer :status, :null =&gt; false, :default =&gt; 0
    t.timestamps
  end
  
  # routes.rb
  resources :friendships, :only =&gt; [:create, :destroy, :index]
  resources :users do
    member do
      get :friends # index-like action returning array of friends
    end
  end
  </code></pre>
  
  <p>... and yes, I have been searching for days :)</p>
  
  <p>I'm working with Rails, but this question stands for any framework. And yes, I know that I have a million ways to "Get 'er done", but I'm looking for the RESTful way of doing this so that I can use any client side framework without having to customize the I/O too much.</p>