PHPackages                             tiannian/presty - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. tiannian/presty

ActiveLibrary[API Development](/categories/api)

tiannian/presty
===============

A simple RESTful API framework

0.1.2(9y ago)0101LGPL-3.0PHPPHP ^5.3.3 || ^7.0

Since Apr 16Pushed 9y ago1 watchersCompare

[ Source](https://github.com/tiannian/presty)[ Packagist](https://packagist.org/packages/tiannian/presty)[ RSS](/packages/tiannian-presty/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependencies (1)Versions (4)Used By (0)

presty
======

[](#presty)

A lightweight RESTful API framework based PHP.

Installation
------------

[](#installation)

If you use composer to manage your project:

```
composer require tiannian/presty

```

If you are using it directly, you can download it into your project or use git:

```
git clone http://github.com/tiannian/presty

```

Requirements
------------

[](#requirements)

- php &gt; 5.3 or php &gt; 7.0

HTTP Server Configuration
-------------------------

[](#http-server-configuration)

You need to configure your http server to use presty.Redirect all requests to the entry file you specified by your http server configuration.

### Nginx

[](#nginx)

If you want to redirect all requests to `/api` to index.php, add the following configuration to the location section.

```
location /api{
	include fastcgi_params;
	fastcgi_pass 127.0.0.1:9000;
	fastcgi_param index.php;
}

```

Usage
-----

[](#usage)

### Entry File

[](#entry-file)

Use composer:

```
require 'vendor/autoload.php';

```

Use directly:

```
require 'path-to-presty/src/app.php';

```

### Path Match

[](#path-match)

Presty will find the file according to the requested path. When the folder does not exist, it looks for a folder that begins with an underscore.When you find the file that requested the path to point, presty will follow ..php to match file.When this file does not exist, it will go to find out if there is a file with an underscore in the path.

Files in the same directory are allowed to have the same name as the folder, but only one file and folder with an underscore allowed in the directory is allowed.

When a file or folder that matches an underscore appears, presty records the name and path in the url\_match of the request array.

### Request Array

[](#request-array)

Request array `$ resty_request` is a global variable, in any php file can be accessed. The request array contains information for each request.

- `url` Request URL
- `url_match` A record of the path and file name
- `query` The query string parameters parsed into an array
- `query_str` Query string
- `charset` The value of Accept-Charset
- `body` The body string parsed into an array by `json_decode`
- `method` Request method
- `headers` Request headers
- `hostname` Remote Hostname
- `ip` Remote IP
- `port` Remote Port

### Response Array

[](#response-array)

The response array `$ resty_response` is a global variable that can be accessed in any php file. The response array can be modified in the php file, and the data is returned to the client based on the data recorded in the array.

- `status` HTTP Status Code
- `headers` Response headers
- `redirect` Redirect URL
- `body` The response body array is parsed as a json string sent to the client

presty
======

[](#presty-1)

一个基于PHP的轻量RESTful API 框架

安装
--

[](#安装)

如果你使用composer环境的项目:

```
composer require tiannian/presty

```

如果你希望直接使用，你可以通过git下载框架

```
git clone http://github.com/tiannian/presty

```

依赖
--

[](#依赖)

- php &gt; 5.3 or php &gt; 7.0

HTTP 服务器配置
----------

[](#http-服务器配置)

您需要配置您的http服务器以使用presty，通过配置将所有请求重定向至你指定的入口文件。

### Nginx

[](#nginx-1)

If you want to redirect all requests to `/` to index.php, add the following configuration to the location section.

```
location /{
	include fastcgi_params;
	fastcgi_pass 127.0.0.1:9000;
	fastcgi_param index.php;
}

```

使用
--

[](#使用)

### 入口文件

[](#入口文件)

使用composer :

```
require 'vendor/autoload.php'

```

直接使用:

```
require 'path-to-presty/src/app.php

```

### 路径匹配

[](#路径匹配)

presty会根据请求路径依次查找文件树，当文件夹不存在，它会寻找以下划线开头的文件夹。查找到请求路径指向的文件时，presty会按照文件名.请求方法.php匹配文件。当此文件不存在，它会去查找路径中是否存在以下划线开头的文件。

同目录下的文件允许与文件夹同名，但同目录下仅允许出现一个以下划线开头的文件和文件夹。

当出现匹配以下划线开头的文件或文件夹时，presty会将对应的名称与路径记录在请求数组的url\_match中。

### 请求数组

[](#请求数组)

请求数组`$resty_request`是一个全局变量，在一个php文件中均可以访问到。请求数组中包含了每一次请求的信息。

- url 请求路径
- url\_match 路径与文件名的对应记录
- query 将查询参数字符串进行解析并以数组的形式返回
- query\_str 查询参数字符串
- charset Accept-Charset值
- body 被json\_decode解析为数组的请求体
- method 请求方法
- headers 请求头数组
- hostname 请求远程主机名
- ip 请求远程地址
- port 请求远程端口

### 响应数组

[](#响应数组)

响应数组`$resty_response`是一个全局变量，在任何一个php文件中均可以访问到。响应数组在php文件中可以修改，修改后会根据数组中记录的数据向客户端返回数据。

- status 返回HTTP状态码
- headers 返回的响应头
- redirect 此次请求会被重定向至指定URL
- body 相应体数组，会被解析为json字符串发送给客户端

###  Health Score

23

—

LowBetter than 26% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~3 days

Total

3

Last Release

3356d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/10502431?v=4)[tiannian](/maintainers/tiannian)[@tiannian](https://github.com/tiannian)

---

Top Contributors

[![tiannian](https://avatars.githubusercontent.com/u/10502431?v=4)](https://github.com/tiannian "tiannian (4 commits)")

---

Tags

apirestful

### Embed Badge

![Health badge](/badges/tiannian-presty/health.svg)

```
[![Health](https://phpackages.com/badges/tiannian-presty/health.svg)](https://phpackages.com/packages/tiannian-presty)
```

###  Alternatives

[nezamy/route

Route - Fast, flexible routing for PHP, enabling you to quickly and easily build RESTful web applications.

21437.8k5](/packages/nezamy-route)[teepluss/api

Laravel 4 Internal Request (HMVC)

7034.1k](/packages/teepluss-api)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
