承接 snype/api-response 相关项目开发

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

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

snype/api-response

最新稳定版本:v2.0.0

Composer 安装命令:

composer require snype/api-response

包简介

A lightweight Laravel package for consistent and elegant JSON API responses. Simplify your controllers with ApiResponse::success() and ApiResponse::error() methods for structured and reusable response formats.

README 文档

README

**# Snype API Response

A lightweight Laravel package for consistent and elegant JSON API responses. Simplify your controllers with ApiResponse::success() and ApiResponse::error() methods for structured and reusable response formats.

Installation

You can install the package via Composer:

composer require snype/api-response

Usage

Success Response

Use the ApiResponse::success() method to return a successful response.

use Snype\ApiResponse\ApiResponse;

public function index()
{
    $data = ['message' => 'Data retrieved successfully'];

    return ApiResponse::success($data, 'Success', 200);
}

This will return a structured JSON response with a success status.

Error Response

Use the ApiResponse::error() method to return an error response.

use Snype\ApiResponse\ApiResponse;

public function store(Request $request)
{
    // Assuming validation fails
    $errors = ['field' => 'This field is required'];

    return ApiResponse::error($errors, 'Validation Error', 422);
}

This will return a structured JSON response with an error status.

Customization

You can easily customize the success and error response structure by extending the ApiResponse class.

Requirements

  • PHP 8.0 or higher
  • Laravel 9.x or 10.x

License

This package is licensed under the MIT License. **

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-01-28