preprio/laravel-sdk
Composer 安装命令:
composer require preprio/laravel-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-sdk 适用场景与选型建议
preprio/laravel-sdk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5.22k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2021 年 02 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「rest」 「laravel」 「prepr」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 preprio/laravel-sdk 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 preprio/laravel-sdk 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 preprio/laravel-sdk 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Prepr PHP SDK
Laravel SDK for the Prepr REST API.
A PSR-7 compatible library for making CRUD API endpoints
Api bundle
Prepr PHP GraphQL SDK
Prepr GraphQL wrapper for Laravel
统计信息
- 总下载量: 5.22k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 8
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-02-23