mennen-online/simple-api-connector 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

mennen-online/simple-api-connector

Composer 安装命令:

composer require mennen-online/simple-api-connector

包简介

Configure each API you want to Connect simply via configuration File

README 文档

README

Description

Are you tired of writing new API Connectors following the same procedures?

Save time using this Package:

Now you are able to connect third party APIs in a simple way: Through Laravels config files.

Installation

composer require mennen-online/simple-api-connector

Usage

Create a new config file in config/api directory, named for example my-shopware6-shop.php Paste the following content into the file:

return [
    'fallback_response_model' => \MennenOnline\SimpleApiConnector\Models\BaseResponseModel::class,
    'base_url' => 'https://example.com/api',
    'authentication' => [
        'type' => 'basic', // basic, bearer, token, digest, client_credentials
        'username' => '', //use for basic and digest
        'password' => '', //use for basic and digest
        'token' => '', //use for bearer and token
        'client_id' => '', //use for client_credentials
        'client_secret' => '', //use for client_credentials
        'authentication_url' => '' //use for client_credentials
    ],
    'endpoints' => [
        'categories' => '/categories',
        'products' => '/products',
        'users/:id' => '/users/:id',
        'users/:user_id/orders/:order_id' => '/users/:user_id/orders/:order_id
    ],
    'response_models' => [
        'categories' => 'Model::class', //Response model for Categories
        'products' => 'Model::class', //Response model for Products
    ]

Now we will explore the single Array keys and their meaning:

  • fallback_response_model => We use this model if no response model is defined for a specific endpoint
  • base_url => The base url of the API
  • authentication.type => The authentication method used for the API
  • authentication.username => The username used for basic and digest authentication
  • authentication.password => The password used for basic and digest authentication
  • authentication.token => The token used for bearer and token authentication
  • authentication.client_id => The client id used for client_credentials authentication
  • authentication.client_secret => The client secret used for client_credentials authentication
  • authentication.authentication_url => The authentication url used for client_credentials authentication
  • endpoints => The endpoints of the API as endpoint_name => endpoint_url
  • response_models => The response models of the API as endpoint_name => response_model

The Package allows GET, POST, PUT and DELETE requests.

To instanciate the API Connector use the following code:

$connector = new \MennenOnline\SimpleApiConnector\Connector\ApiConnector('my-shopware6-shop');

// To Call the API use the following code:

// GET
$response = $connector->get('categories');

// POST
$response = $connector->post('categories', ['name' => 'My Category']);

// PUT
$response = $connector->put('categories/1', ['name' => 'My Category']);

// DELETE
$response = $connector->delete('categories/1');


// To use URLs with names ID
$response = $connector->get('users/:id', [':id' => 1]);

// To use URLs with multiple names ID
$response = $connector->get('users/:user_id/orders/:order_id', [':user_id' => 1, ':order_id' => 1]);

mennen-online/simple-api-connector 适用场景与选型建议

mennen-online/simple-api-connector 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6 次下载、GitHub Stars 达 1, 最近一次更新时间为 2023 年 10 月 16 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 mennen-online/simple-api-connector 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 mennen-online/simple-api-connector 我们能提供哪些服务?
定制开发 / 二次开发

基于 mennen-online/simple-api-connector 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 6
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 11
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-3.0-or-later
  • 更新时间: 2023-10-16