mpstr24/laravel-api-responses 问题修复 & 功能扩展

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

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

mpstr24/laravel-api-responses

Composer 安装命令:

composer require mpstr24/laravel-api-responses

包简介

Laravel package for formatted API responses.

README 文档

README

This package provides API response functions via a trait to help improve consistency of API response codes across your projects.

GitHub Actions Workflow Status Packagist Version Packagist Downloads

Features

  • Pre-made functions of the most common API responses.

Installation

Install the package via Composer:

composer require mpstr24/laravel-api-responses

Usage/Examples

First add the trait to your controller.

use ApiResponseTrait;

All methods, except from "No Content" allow for a message and data to be returned. Custom messages also allow you to choose the status code.

Examples of each below.

Success - 200

public function success()
{
  return $this->apiSuccess();
}

Created - 201

public function created()
{
    return $this->apiCreated();
}

Accepted - 202

public function accepted()
{
    return $this->apiAccepted();
}

No Content - 204

public function noContent()
{
    return $this->apiNoContent();
}

Bad Request - 400

public function badRequest()
{
    return $this->apiBadRequest();
}

Unauthorized - 401

public function unauthorized()
{
    return $this->apiUnauthorized();
}

Forbidden - 403

public function forbidden()
{
    return $this->apiForbidden();
}

Not Found - 404

public function notFound()
{
    return $this->apiNotFound();
}

Teapot - 418

public function teapot()
{
    return $this->apiTeapot();
}

Unprocessable - 422

public function unprocessable()
{
    return $this->apiUnprocessable();
}

Too Many Requests - 429

public function tooManyRequests()
{
    return $this->apiTooManyRequests();
}

Server Error - 500

public function serverError()
{
    return $this->apiInternalServerError();
}

Custom response

public function apiCustomResponse()
{
    return $this->apiCustom('Custom', null, 201);
}

Roadmap

  • Support for resources
  • Expand into more helpful API features
  • Larastan goals
    • 5
    • 6
    • 7
    • 8
    • 9

License

MIT

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-03-10

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固