Dolibarr / dolibarr

Dolibarr ERP CRM is a modern software package to manage your company or foundation's activity (contacts, suppliers, invoices, orders, stocks, agenda, accounting, ...). it's an open source Web application (written in PHP) designed for businesses of any sizes, foundations and freelancers.
https://www.dolibarr.org
GNU General Public License v3.0
5.24k stars 2.72k forks source link

Multiple API routes in the same module #27601

Open Monsieur76 opened 7 months ago

Monsieur76 commented 7 months ago

Feature Request

added several api files in the same module to make it more readable

Use case

I have a module with several different types of routes created

Suggested implementation

I will be brief Here are the ones that I added personally to search for the different files of but external module and to be able to create several different routes and several different api_XXX files in a single module

I wanted to know what when to think about community Thank you Sorry if my English is not very good

JonBendtsen commented 7 months ago

I think it is unclear what you are asking for

rycks commented 6 months ago

Hello @Monsieur76 and @JonBendtsen

i have a dream with PSR-4 for api routes at least for modules. PSR-4 will not imply "composer" but with PSR-4 we could adopt a more "classic way" of file naming convention and objects manipulation.

as @Monsieur76 try to explain, here is an example of a api_file.class.php made with module builder:

use Luracast\Restler\RestException;

/**
 * \file    indirectcustomers/class/api_indirectcustomers.class.php
 * \ingroup indirectcustomers
 * \brief   File for API management of saleshistory.
 */

/**
 * API class for indirectcustomers saleshistory
 *
 * @access protected
 * @class  DolibarrApiAccess {@requires user,external}
 */
class IndirectCustomersApi extends DolibarrApi
{
    /**
     * @var SalesHistory $saleshistory {@type SalesHistory}
     */
    public $saleshistory;

    /*begin methods CRUD*/
    /*CRUD FOR SALESHISTORY*/

    /**
     * Get properties of a saleshistory object
     *
     * Return an array with saleshistory informations
     *
     * @param   int     $id             ID of saleshistory
     * @return  Object                  Object with cleaned properties
     *
     * @url GET saleshistory/{id}
     *
     * @throws RestException 401 Not allowed
     * @throws RestException 404 Not found
     */
    public function get($id)
         {
         }
.../...

ok, that "get" function is entry point for ONE object from my module, but now how could we implement an OTHER get entry point for an OTHER object of the same module ?

rycks commented 6 months ago

@eldy as you explain to me on french forum, here is one of the point i try to explain on https://www.dolibarr.fr/forum/t/rfc-api-dolibarr-applications-mobiles/45780/18