{"id":13733974,"url":"https://github.com/zepgram/module-rest","last_synced_at":"2026-01-16T17:00:08.192Z","repository":{"id":45234307,"uuid":"424770404","full_name":"zepgram/module-rest","owner":"zepgram","description":"Provide a module to industrialize API REST request with dependency injection using Guzzle library","archived":false,"fork":false,"pushed_at":"2026-01-15T11:30:10.000Z","size":62,"stargazers_count":12,"open_issues_count":0,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2026-01-15T16:08:26.060Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zepgram.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2021-11-04T23:33:11.000Z","updated_at":"2026-01-15T11:03:21.000Z","dependencies_parsed_at":"2024-05-06T11:52:59.140Z","dependency_job_id":"8f6b17c8-4abd-42ae-8576-4f24050f810f","html_url":"https://github.com/zepgram/module-rest","commit_stats":{"total_commits":6,"total_committers":1,"mean_commits":6.0,"dds":0.0,"last_synced_commit":"b3351690d382f3369505cae7c5945538ae060579"},"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"purl":"pkg:github/zepgram/module-rest","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zepgram%2Fmodule-rest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zepgram%2Fmodule-rest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zepgram%2Fmodule-rest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zepgram%2Fmodule-rest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zepgram","download_url":"https://codeload.github.com/zepgram/module-rest/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zepgram%2Fmodule-rest/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28480081,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-16T11:59:17.896Z","status":"ssl_error","status_checked_at":"2026-01-16T11:55:55.838Z","response_time":107,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T03:00:51.424Z","updated_at":"2026-01-16T17:00:07.988Z","avatar_url":"https://github.com/zepgram.png","language":"PHP","funding_links":[],"categories":["Open Source Extensions"],"sub_categories":["Development Utilities"],"readme":"# Zepgram Rest\n\n## Overview\nZepgram Rest is a technical module designed to streamline the development of REST API integrations in Magento 2 projects.\nUtilizing the Guzzle HTTP client for dependency injection, this module offers a robust set of features aimed at reducing \nboilerplate code, improving performance, and enhancing debugging capabilities. By centralizing REST API interactions and \nleveraging Magento's built-in systems, Zepgram Rest simplifies the implementation process for developers.\n\n## Features\nZepgram Rest provides several key features to aid Magento developers in creating and managing RESTful services:\n- \u003cb\u003eAvoid Code Duplication:\u003c/b\u003e Minimize repetitive code with a straightforward setup in di.xml. Implement your REST API integrations with just one class creation, streamlining the development process.\n- \u003cb\u003eCentralized Configuration:\u003c/b\u003e Manage all your REST web services configurations in one place, ensuring consistency and ease of maintenance.\n- \u003cb\u003eBuilt-in Registry and Cache:\u003c/b\u003e Take advantage of Magento's native cache mechanisms and dedicated registry to boost your API's performance and security. This feature helps in efficiently managing data retrieval and storage, reducing the load on your server.\n- \u003cb\u003eGeneric Logger:\u003c/b\u003e Debugging is made effortless with an inclusive logging system. Enable the debug mode to log detailed information about your API calls, including parameters, requests, and responses, facilitating easier troubleshooting.\n- \u003cb\u003eData Serialization:\u003c/b\u003e Declare whether your requests and results should be JSON serialized or not. This flexibility prevents the need for multiple serializer implementations, accommodating various API requirements with ease.\n\n## Installation\n\n```\ncomposer require zepgram/module-rest\nbin/magento module:enable Zepgram_Rest\nbin/magento setup:upgrade\n```\n\n## Guideline with ApiPool\n\n1. Create a RequestAdapter class for your service extending abstract class `Zepgram\\Rest\\Model\\RequestAdapter`,\n   this class represent your service contract adapter:\n   - **public const SERVICE_ENDPOINT**: define the service endpoint\n   - **dispatch(DataObject $rawData)**: initialize data that you will adapt to request the web service\n   - **getBody()**: implement body request\n   - **getHeaders()**: implement headers\n   - **getUri()**: implement uri endpoint (used to handle dynamic values)\n   - **getCacheKey()**: implement cache key for your specific request (you must define a unique key)\n1. Create a system.xml, and a config.xml with a dedicated **configName**:\n   - **section**: `rest_api`\n   - **group_id**: `$configName`\n   - **fields**:\n      - `base_uri`\n      - `timeout`\n      - `is_debug`\n      - `cache_ttl`\n1. Declare your service in di.xml by implementing `Zepgram\\Rest\\Service\\ApiProvider` as VirtualClass, you can configure\n   it by following the [ApiProviderConfig](#configuration)\n1. Declare your RequestAdapter and ApiProvider in `Zepgram\\Rest\\Service\\ApiPoolInterface`:\n    - Add a new item in `apiProviders[]`:\n      - The **key** is your custom RequestAdapter full namespace\n      - The **value** is your ApiProvider as a VirtualClass\n1. Inject ApiPoolInterface in the class that will consume your API and use `$this-\u003eapiPool-\u003eexecute(RequestAdapter::class, $rawData)` where:\n    - **RequestAdapter::class** represents the request adapter declared in `apiProviders[]`\n    - **$rawData** is an array of dynamic data that will be dispatch in `dispatch()` method\n\n## Basic guideline implementation\n\nInstead of declaring your class in `Zepgram\\Rest\\Service\\ApiPoolInterface` you can also directly inject\nyour ApiProvider in a dedicated class:\n```xml\n\u003c?xml version=\"1.0\"?\u003e\n\u003cconfig xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n        xsi:noNamespaceSchemaLocation=\"urn:magento:framework:ObjectManager/etc/config.xsd\"\u003e\n    \u003c!-- rest api --\u003e\n    \u003cvirtualType name=\"CustomApiProvider\" type=\"Zepgram\\Rest\\Service\\ApiProvider\"\u003e\n        \u003carguments\u003e\n            \u003cargument name=\"requestAdapter\" xsi:type=\"object\"\u003eZepgram\\Sales\\Rest\\FoxtrotOrderRequestAdapter\u003c/argument\u003e\n            \u003cargument name=\"configName\" xsi:type=\"string\"\u003efoxtrot\u003c/argument\u003e\n        \u003c/arguments\u003e\n    \u003c/virtualType\u003e\n    \u003ctype name=\"My\\Custom\\Model\\ConsumerExample\"\u003e\n        \u003carguments\u003e\n            \u003cargument name=\"apiProvider\" xsi:type=\"object\"\u003eCustomApiProvider\u003c/argument\u003e\n        \u003c/arguments\u003e\n    \u003c/type\u003e\n\u003c/config\u003e\n```\n\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nnamespace My\\Custom\\Model\\Api;\n\nuse Zepgram\\Rest\\Exception\\InternalException;\nuse Zepgram\\Rest\\Exception\\ExternalException;\nuse Zepgram\\Rest\\Service\\ApiPoolInterface;\nuse Zepgram\\Rest\\Service\\ApiProviderInterface;\nuse Zepgram\\Sales\\Api\\OrderRepositoryInterface;\n\nclass ConsumerExample\n{\n    public function __construct(\n        private OrderRepositoryInterface $orderRepository,\n        private ApiProviderInterface $apiProvider\n    ) {}\n\n    /**\n     * @param int $orderId\n     * @return array \n     */\n    public function execute(int $orderId): array\n    {\n        // get raw data\n        $order = $this-\u003eorderRepository-\u003eget($orderId);\n        // send request\n        $result = $this-\u003eapiProvider-\u003eexecute(['order' =\u003e $order]);\n        \n        return $result;\n    }\n}\n```\n\n## Configuration\n\n### Store config\n\n![562](https://user-images.githubusercontent.com/16258478/140424659-f9e1f593-c75f-40fd-aafa-935984c3ae10.png)\nIf you do not declare specific configuration, the request will fall back on default configuration.\nTo override the default config, you must follow this system config pattern: `rest_api/%configName%/base_uri`\n\n### XML config\n\nYou can configure your service with `Zepgram\\Rest\\Service\\ApiProvider` by creating a\nVirtualClass and customize its injections for your needs by following the below configuration:\n\n| Variable name  |  Type   | Default value  | Is Optional |                   Description                    |\n|:--------------:|:-------:|:--------------:|:-----------:|:------------------------------------------------:|\n|   configName   | string  |    default     |     no      |  Value to retrieve group id from system config   |\n| requestAdapter | object  | RequestAdapter |     no      | Adapter class to build and customize the request |\n|   validator    | object  |      null      |     yes     |          Validate the service contract           |\n|     method     | string  |      GET       |     yes     |                  Request method                  |\n| isJsonRequest  | boolean |      true      |     yes     |           Parse request array to json            |\n| isJsonResponse | boolean |      true      |     yes     |          Parse response string to array          |\n|    isVerify    | boolean |      true      |     yes     |       Enable SSL certificate verification        |\n\n## Implementation\n\nHere is a simple implementation example with a service called **Foxtrot** using the order object as rawData:\n\n**FoxtrotOrderRequestAdapter.php**\n\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nnamespace Zepgram\\Sales\\Rest;\n\nuse Magento\\Framework\\DataObject;\nuse Magento\\Sales\\Api\\Data\\OrderInterface;\nuse Zepgram\\Rest\\Model\\RequestAdapter;\n\nclass FoxtrotOrderRequestAdapter extends RequestAdapter\n{\n    /** @var string */\n    public const SERVICE_ENDPOINT = 'v1/order/';\n    \n    /** @var OrderInterface */\n    private $order;\n\n    /**\n     * {@inheritDoc}\n     */\n    public function dispatch(DataObject $rawData): void\n    {\n        $this-\u003eorder = $rawData-\u003egetOrder();\n    }\n\n    /**\n     * {@inheritDoc}\n     */\n    public function getBody(): array\n    {\n        return [\n            'orderId' =\u003e $this-\u003eorder-\u003egetEntityId(),\n            'customer' =\u003e $this-\u003eorder-\u003egetCustomerEmail(),\n            'orderTotal' =\u003e $this-\u003eorder-\u003egetGrandTotal(),\n            'version' =\u003e '1.0',\n        ];\n    }\n\n    /**\n     * {@inheritDoc}\n     */\n    public function getCacheKey(): ?string\n    {\n        return $this-\u003eorder-\u003egetEntityId();\n    }\n}\n```\n\n**system.xml**\n\n```xml\n\u003c?xml version=\"1.0\"?\u003e\n\u003cconfig xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n        xsi:noNamespaceSchemaLocation=\"urn:magento:module:Magento_Config:etc/system_file.xsd\"\u003e\n    \u003csystem\u003e\n        \u003csection id=\"rest_api\"\u003e\n            \u003cgroup id=\"foxtrot\" translate=\"label\" type=\"text\" sortOrder=\"10\" showInDefault=\"1\" showInWebsite=\"0\"\n                   showInStore=\"0\"\u003e\n                \u003clabel\u003eFoxtrot\u003c/label\u003e\n                \u003cfield id=\"base_uri\" translate=\"label\" type=\"text\" sortOrder=\"1\" showInDefault=\"1\" showInWebsite=\"0\"\n                       showInStore=\"0\" canRestore=\"1\"\u003e\n                    \u003clabel\u003eBase URI\u003c/label\u003e\n                \u003c/field\u003e\n                \u003cfield id=\"timeout\" translate=\"label\" type=\"text\" sortOrder=\"1\" showInDefault=\"1\" showInWebsite=\"0\"\n                       showInStore=\"0\" canRestore=\"1\"\u003e\n                    \u003clabel\u003eTimeout\u003c/label\u003e\n                \u003c/field\u003e\n                \u003cfield id=\"cache_ttl\" translate=\"label\" type=\"text\" sortOrder=\"5\" showInDefault=\"1\" showInWebsite=\"0\"\n                       showInStore=\"0\" canRestore=\"1\"\u003e\n                    \u003clabel\u003eCache TTL\u003c/label\u003e\n                \u003c/field\u003e\n                \u003cfield id=\"is_debug\" translate=\"label\" type=\"select\" sortOrder=\"10\" showInDefault=\"1\" showInWebsite=\"0\"\n                       showInStore=\"0\" canRestore=\"1\"\u003e\n                    \u003clabel\u003eEnable Debug\u003c/label\u003e\n                    \u003csource_model\u003eMagento\\Config\\Model\\Config\\Source\\Yesno\u003c/source_model\u003e\n                \u003c/field\u003e\n            \u003c/group\u003e\n        \u003c/section\u003e\n    \u003c/system\u003e\n\u003c/config\u003e\n```\n\n**config.xml**\n\n```xml\n\u003c?xml version=\"1.0\"?\u003e\n\u003cconfig xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"urn:magento:module:Magento_Store:etc/config.xsd\"\u003e\n    \u003cdefault\u003e\n        \u003crest_api\u003e\n            \u003cfoxtrot\u003e\n                \u003cbase_uri\u003ehttps://foxtrot.service.io\u003c/base_uri\u003e\n                \u003ctimeout\u003e30\u003c/timeout\u003e\n                \u003ccache_ttl\u003e7200\u003c/cache_ttl\u003e\n                \u003cis_debug\u003e1\u003c/is_debug\u003e\n            \u003c/foxtrot\u003e\n        \u003c/rest_api\u003e\n    \u003c/default\u003e\n\u003c/config\u003e\n```\n\n**di.xml**\n\n```xml\n\u003c?xml version=\"1.0\"?\u003e\n\u003cconfig xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n        xsi:noNamespaceSchemaLocation=\"urn:magento:framework:ObjectManager/etc/config.xsd\"\u003e\n   \u003c!-- rest api --\u003e\n   \u003cvirtualType name=\"FoxtrotOrderApiProvider\" type=\"Zepgram\\Rest\\Service\\ApiProvider\"\u003e\n      \u003carguments\u003e\n         \u003cargument name=\"requestAdapter\" xsi:type=\"object\"\u003eZepgram\\Sales\\Rest\\FoxtrotOrderRequestAdapter\u003c/argument\u003e\n         \u003cargument name=\"configName\" xsi:type=\"string\"\u003efoxtrot\u003c/argument\u003e\n      \u003c/arguments\u003e\n   \u003c/virtualType\u003e\n   \u003ctype name=\"Zepgram\\Rest\\Service\\ApiPoolInterface\"\u003e\n      \u003carguments\u003e\n         \u003cargument name=\"apiProviders\" xsi:type=\"array\"\u003e\n            \u003citem name=\"Zepgram\\Sales\\Rest\\FoxtrotOrderRequestAdapter\" xsi:type=\"object\"\u003eFoxtrotOrderApiProvider\u003c/item\u003e\n         \u003c/argument\u003e\n      \u003c/arguments\u003e\n   \u003c/type\u003e\n\u003c/config\u003e\n```\n\n**OrderDataExample.php**\n\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nnamespace Zepgram\\Sales\\Model;\n\nuse Zepgram\\Rest\\Exception\\InternalException;\nuse Zepgram\\Rest\\Exception\\ExternalException;\nuse Zepgram\\Rest\\Service\\ApiPoolInterface;\nuse Zepgram\\Sales\\Api\\OrderRepositoryInterface;\nuse Zepgram\\Sales\\Rest\\FoxtrotOrderRequestAdapter;\n\nclass OrderDataExample\n{\n    public function __construct(\n        private OrderRepositoryInterface $orderRepository,\n        private ApiPoolInterface $apiPool\n    ) {}\n\n    /**\n     * @param int $orderId\n     * @throws MyAweSomeTechnicalException\n     * @throws MyAwesomeBusinessException\n     */\n    public function execute(int $orderId): void\n    {\n        try {\n            // get raw data\n            $order = $this-\u003eorderRepository-\u003eget($orderId);\n            // send request\n            $result = $this-\u003eapiPool-\u003eexecute(FoxtrotOrderRequestAdapter::class, ['order' =\u003e $order]);\n            // handle result\n            $order-\u003esetFoxtrotData($result);\n            $this-\u003eorderRepository-\u003esave($order);\n        } catch (InternalException $e) {\n            $context['context_error'] = 'Magento request is wrong, foxtrot order service could not handle it'\n            // service rejected request for business reason: do something (log, throw, errorMessage..)\n            throw MyAwesomeBusinessException(__('Bad request error'), $e);\n        } catch (ExternalException $e) {\n             $context['context_error'] = 'We could not reach foxtrot order service'\n             // service is unavailable due to technical reason: do something (log, throw, errorMessage..)\n             $this-\u003elogger-\u003eerror($e, $context);\n             throw MyAwesomeTechnicalException(__('Foxtrot server error'), $e);\n        }\n    }\n}\n```\n## Log \u0026 Sensitive Data\n\nThis module includes a built-in Monolog Processor: [SensitiveDataProcessor.php](Logger/SensitiveDataProcessor.php)\nDepending on your `MAGE_MODE` environment variable, data will be automatically obfuscated if log key contains those keys:\n- `password`\n- `username`\n- `user`\n- `token`\n- `key`\n- `secret`\n- `hash`\n- `hmac`\n- `sha`\n- `sign`\n- `authorization`\n- `jwt`\n- `access`\n- `auth`\n- `sso`\n- `passphrase`\n- `ssh`\n- `pin`\n- `cvv`\n- `ccv`\n- `cvc`\n- `card`\n\nThis class can be customized with `di.xml` by:\n- Activating the processor with parameter `$isEnabled`, otherwise it will only be enabled if `MAGE_MODE === 'production'` \n- Adding custom keys by using `$sensitiveKeys` parameter\n- Overriding the default keys by using `$overrideSensitiveKeys` parameter\n- Modify the placeholder for sensitive data by setting `$redactionPlaceholder`\n\n## Issues \u0026 Improvements\n\nIf you encountered an issue during installation or with usage, please report it on this github repository.\u003cbr\u003e\nIf you have good ideas to improve this module, feel free to contribute.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzepgram%2Fmodule-rest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzepgram%2Fmodule-rest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzepgram%2Fmodule-rest/lists"}