承接 lakondev/simple-api-service 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

lakondev/simple-api-service

最新稳定版本:v1.0.0

Composer 安装命令:

composer require lakondev/simple-api-service

包简介

Generic API service to simplify HTTP requests in Laravel

README 文档

README

A lightweight, Guzzle-based HTTP API wrapper for Laravel. Simplifies making API calls without having to write boilerplate code for curl, headers, or token handling.

Installation

You can install the package via Composer:

composer require lakondev/simple-api-service

Usage

1. Initialize the Service

// Import the service class
use SimpleApiService\SimpleApiService;

// Create a new instance of the service
$api = new SimpleApiService();

2. Configuration

// Define the configuration array with base_url and optional token
$config = [
    'base_url' => 'https://jsonplaceholder.typicode.com', // Base URL of the API
    'token' => null, // Optional token (set if required by the API)
];

3. GET Request

// Create the complete URL for the specific endpoint
$url = $api->getApiUrl($config, 'todos/1');

// Prepare request options, including headers
$options = $api->getRequestOptions($config);

// Execute GET request to the API
$response = $api->executeRequest('GET', $url, $options);

// Output the API response
dd($response);

4. POST Request

// Define the endpoint URL
$url = $api->getApiUrl($config, 'posts');

// Define request body to send in POST request
$body = [
    'json' => [
        'title' => 'foo',
        'body' => 'bar',
        'userId' => 1,
    ]
];

// Merge headers with request body
$options = $api->getRequestOptions($config, $body);

// Send POST request
$response = $api->executeRequest('POST', $url, $options);

// Output the response
dd($response);

Requirements

  • PHP >= 8.0
  • Laravel 9+
  • guzzlehttp/guzzle >= 7.0

License

This package is open-sourced software licensed under the MIT license.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Unknown
  • 更新时间: 2025-05-04