thazh/api-light 问题修复 & 功能扩展

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

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

thazh/api-light

最新稳定版本:1.0.0

Composer 安装命令:

composer require thazh/api-light

包简介

A lightweight library is used to build a secure REST API in PHP.

README 文档

README

A lightweight library is used to build a secure REST API in PHP.

Features

The main features provided by this library are:

  • Easy to use
  • Support all the PHP versions
  • Required field validation
  • Basic authentication
  • Support multiple content types
  • Support all the request methods

Quick Start

Install the library using composer:

composer require thazh/api-light

A sample PHP API to validate and process the input data and print the response data

<?php

use Thazh\ApiLight\RestApi;

$options = array(
    'content_type' => 'application/json',
    'request_method' => 'POST',
    'credentials' => array(
        'testuser' => 'TestPwd@123',
    ),
    'required_fields' => array(
        'rollno',
        'name',
    )
);

$obj = new RestApi($options);

/* Custom business logic */
$output_data = "Hi, " . $obj->request['name'] . "! Your roll no is " . $obj->request['rollno'];

/* Set code 200 for the success response */
$obj->code = 200;

/* Set API response data */
$obj->data = $output_data;

/* Print the API response data */
$obj->print();

Post parameters:

{
    "rollno": 10001,
    "name": "Saravanan S"
}

The above sample PHP API outputs the below response

{
    "code": 200,
    "status": "success",
    "data": "Hi, Saravanan S! Your roll no is 10001"
}

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-05-17