I have done following way:
Step 1: creating api2.xml in app\code\local\YourPackageName\Restapi\etc as shown beelow :
<?xml version="1.0" encoding="utf-8"?>
<config>
<api2>
<resource_groups>
<restapi translate="title" module="restapi">
<title>Restapi</title>
<sort_order>10</sort_order>
</restapi>
</resource_groups>
<resources>
<addtocart translate="title" module="restapi">
<group>restapi</group>
<model>restapi/api2_addtocart</model>
<title>Add to Cart</title>
<sort_order>10</sort_order>
<privileges>
<guest>
<create>1</create>
<retrieve>1</retrieve>
<update>1</update>
<delete>1</delete>
</guest>
</privileges>
<attributes translate="data" module="restapi">
<data>Data</data>
<productid>Product Id</productid>
<itemid>Item Id</itemid>
<productname>Product Name</productname>
<qty>Qty</qty>
<price>Price</price>
<options>Options</options>
</attributes>
<routes>
<route_collection>
<route>/addToCart</route>
<action_type>collection</action_type>
</route_collection>
<route_entity>
<route>/addToCart/:device_id/:product_id/:qty</route>
<action_type>entity</action_type>
</route_entity>
</routes>
<versions>1</versions>
</addtocart>
</resources>
</api2>
Step2: Creating model in app\code\local\YourPackageName\Restapi\Model\Api2\Addtocart.php as shown bellow :
class YourPackageName_Restapi_Model_Api2_Addtocart extends Mage_Api2_Model_Resource
{
}
Step3: Finally extending the model addtocart for Guest user in app\code\local\Bluehorse\Restapi\Model\Api2\Addtocart\Rest\Guest\V1.php as shown bellow :
class YourPackageName_Restapi_Model_Api2_Addtocart_Rest_Guest_V1 extends YourPackageName_Restapi_Model_Api2_Addtocart
{
protected function _create(array $data){
echo '<pre>';
print_r($data);
exit;
}
protected function _update(array $data){
echo '<pre>';
print_r($data);
exit;
}
}
** POST url:/api/rest/addToCart
** PUT url: /api/rest/addToCart/[device_id]/[product_id]/[qty]
Hope this will help you.