🎉 New Integrations Added to the PrestaShop Mobile App!

Create REST API for PrestaShop Modules

Add REST API support to existing PrestaShop front-end controllers

Binshops REST API module gives you the ability to easily write your PrestaShop REST API endpoints with existing front controllers.

To add API to your PrestaShop module, you can create a new front-controller or you can add your API to the existing front-controllers within a module.

Create REST API for PrestaShop Module

  1. Install PrestaShop REST API module

  2. Create a front controller within your module. You can follow these instructions (or you can use existing controllers).

  3. The module adds four methods to create REST APIs. Use the following methods to process your desired method type:
    • processGetRequest to process GET
    • processPostRequest to process POST
    • processPutRequest to process PUT
    • processDeleteRequest to process DELETE

  4. You can return your data inside the methods. Sample code:
        protected function processGetRequest(){
         //your logic
    
            return [
                'success' => true,
                'code' => 200,
                'psdata' => null, //your data
                'message' => "Hello REST API!",
            ];
        }
    

  5. Now you can call your endpoint:
    https://yourdomain.tld/rest/{yourmodule}/{yourcontroller}

    rest is keyword
    {yourmodule} type your module name
    {yourcontroller} type your controller name

Your API structure

Actually, Binshops REST module exposes API for PrestaShop core functionalities, exposes some additional useful APIs (especially in Pro version), esposes API for some of the native modules and adds API functionality to your PrestaShop modules.

So, if you need to write an API you should do it inside your module.


Posted 1 year ago by Sam Berry