在扩展Magento Rest API的同时启用多个端点/路由

I want two endpoints for my custom api which are

  • Create custom rules in a magento cart (URL= magento.com/coupondemo/generate)
  • Create coupon codes for a particular rule (URL= magento.com//coupondemo/rules/:rule_id/codes)

I've followed this tutorial to and coupon codes in Magento and I have code that can create a rule in Magento too. However, I've no clue how to create the two endpoints in my custom rest api as I am only able to create one.

I have the following routes in api2.xml

<routes>
    <route_collection>
        <route>/coupondemo/generate</route>
        <action_type>entity</action_type>
    </route_collection>
    <route_collection>
        <route>/coupondemo/rules/:rule_id/codes</route>
        <action_type>collection</action_type>
    </route_collection>
</routes>

my v1.php's skeleton is as follows

<?php
/* Coupon AutoGen REST API
*
* @category CouponDemo
* @package CouponDemo_AutoGen
* @author Chuck Hudson (used with permission). For more recipes, see Chuck's book http://shop.oreilly.com/product/0636920023968.do
*/

class CouponDemo_AutoGen_Model_Api2_Coupon_Rest_Admin_V1 extends CouponDemo_AutoGen_Model_Api2_Coupon
{
    /**
     * Generate one or more coupon codes using the Generate Coupons rule defined in Magento.
     * Expected parameters are:
     * {
     *    'qty': int, - number of coupon codes to instruct Magento to generate
     *    'length': int, - length of each generated coupon code
     *    'format': string, - alphanum (for alphanumeric codes), alpha (for alphabetical codes), and num (for numeric codes)
     * }
     *
     * @param array $couponData
     * @return string|void
     */
    protected function _create($couponData)
    {

    }

    protected function _retrieveCollection()
    {        

    }

    protected function _retrieve($couponDatas)
    {

    }
}

The problem is that both the routes call the _create methods in my v1.php. I want to have the first route call a custom method with an array as a parameter. So how can I do that?

I tried using this route

<!-- Call For V1.php _retrieve() -->
<route_entity_count>
    <route>/coupondemo/generate</route>
    <action_type>entity</action_type>
</route_entity_count>

which calls the _retrieve method but it doesn't allow the parameter to be passed in. How should I handle the first route then?