preprio/laravel-rest-sdk 问题修复 & 功能扩展

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

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

preprio/laravel-rest-sdk

Composer 安装命令:

composer require preprio/laravel-rest-sdk

包简介

Laravel SDK for the Prepr REST API.

README 文档

README

This Laravel package is a provider for the Prepr REST API.

Basics

  • The SDK on GitHub
  • Compatible with Laravel v5x, v6x, v7x, v8x, v9x, v10x, v11x, v12x.
  • Requires GuzzleHttp 7.3.X, and for version 3.0 and above PHP 8.x is required.

Installation

You can install the Provider as a composer package.

For Laravel v10x, v11x and Laravel v12x

composer require preprio/laravel-rest-sdk:"^4.0"

For Laravel v9x

composer require preprio/laravel-rest-sdk:"^2.0"

For Laravel v8x

composer require preprio/laravel-rest-sdk:"^1.3"

Other versions

composer require preprio/laravel-rest-sdk:"1.1"

Publish config

Publish prepr.php config

php artisan vendor:publish --provider="Preprio\PreprServiceProvider"

Set up your .env file configuration

You can set the default configuration in your .env file of you Laravel project.

PREPR_URL=https://cdn.prepr.io/
PREPR_TOKEN={{ACCESS_TOKEN}}

Laravel local caching

To make use of the caching feature of Laravel, add the following parameters to your .env file.

PREPR_CACHE=true
PREPR_CACHE_TIME=1800

Optional options

PREPR_TIMEOUT=30
PREPR_CONNECT_TIMEOUT=10

Making your first request

Let's start with getting all content items from your Prepr Environment.

<?php

use Preprio\Prepr;

$apiRequest = new Prepr;

$apiRequest
    ->path('publications')
    ->query([
        'fields' => 'items'
    ])
    ->get();

if($apiRequest->getStatusCode() == 200) {

    print_r($apiRequest->getResponse());
}

To get a single content item, pass the Id to the request.

<?php

use Preprio\Prepr;

$apiRequest = new Prepr;

$apiRequest
    ->path('publications/{id}', [
        'id' => '1236f0b1-b26d-4dde-b835-9e4e441a6d09'
    ])
    ->query([
        'fields' => 'items'
    ])
    ->get();

if($apiRequest->getStatusCode() == 200) {

    print_r($apiRequest->getResponse());
}

Optional path parameters

Use {param?} for optional route segments (similar to Laravel route syntax). When the value is null or the key is missing, the segment is omitted from the path. Required placeholders ({param}) log a warning when the value is missing or null, and the path is normalized (no trailing slashes).

An empty string ('') is treated as a provided value, not as missing.

$apiRequest = (new Prepr)
    ->path('tags/{id?}', [
        'id' => $id,
    ])
    ->get();

Override the AccessToken in a request

The authorization can also be set for one specific request ->url('url')->authorization('token').

Autopaging

$apiRequest = (new Prepr)
    ->path('publications')
    ->query([
        'limit' => 200 // optional
    ])
    ->autoPaging();

if($apiRequest->getStatusCode() == 200) {
    dump($apiRequest->getResponse());
}

Create, Update & Destroy

Post

$apiRequest = (new Prepr)
    ->path('publications')
    ->params([
        'body' => 'Example'
    ])
    ->post();

if($apiRequest->getStatusCode() == 201) {
    dump($apiRequest->getResponse());
}

Put (Update)

$apiRequest = (new Prepr)
    ->path('publications')
    ->params([
        'body' => 'Example'
    ])
    ->put();

if($apiRequest->getStatusCode() == 200) {
    dump($apiRequest->getResponse());
}

Patch (Update)

$apiRequest = (new Prepr)
    ->path('publications')
    ->params([
        'body' => 'Example'
    ])
    ->patch();

if($apiRequest->getStatusCode() == 200) {
    dump($apiRequest->getResponse());
}

Delete

$apiRequest = (new Prepr)
    ->path('publications/{id}',[
        'id' => 1
    ])
    ->delete();

if($apiRequest->getStatusCode() == 204) {
    // Deleted.
}

Multipart/Chunk upload

  • Option 1
use Illuminate\Support\Facades\Storage;

$source = Storage::readStream('image.jpg');

$apiRequest = (new Prepr)
    ->path('assets')
    ->params([
      'body' => 'Example',
    ])
    ->file($source);

if($apiRequest->getStatusCode() == 200) {
    dump($apiRequest->getResponse());
}
  • Option 2
use Illuminate\Support\Facades\Storage;

$source = Storage::get('image.jpg');

$apiRequest = (new Prepr)
    ->path('assets')
    ->params([
      'body' => 'Example',
    ])
    ->file($source, 'image.jpg');

if($apiRequest->getStatusCode() == 200) {
    dump($apiRequest->getResponse());
}

Debug

For debug you can use getRawResponse()

preprio/laravel-rest-sdk 适用场景与选型建议

preprio/laravel-rest-sdk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.56k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2023 年 05 月 22 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「rest」 「laravel」 「prepr」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

围绕 preprio/laravel-rest-sdk 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 2
  • Watchers: 3
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-05-22