百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
O

oink

> 编程语言
开源

oink.php 是一个单文件 PHP 库,可用于轻松构建 API。

319 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

oink.php 是一个单文件 PHP 库,可用于轻松构建 API。

oink.php

oink.php is a free and open source API wrapper for PHP, in a single 7kB file.

Installation

You can install it by downloading the oink.php file and including it in your project. It doesn't have dependencies and is compatible with PHP 8.0 or later.

You will need to make all requests go through your index.php file. This can be done by using an .htaccess file, a web.config file, or by configuring your web server. You can find examples of .htaccess files in the examples directory.

Basic Usage

This minimal example shows how to create a simple blog API:

index.php

php
require_once 'oink.php';

Oink\serve('endpoints.php');

endpoints.php

…

Let's see what's happening here:

  • Routing: When calling serve, it looks at all function names defined in the file passed as an argument and creates an endpoint for each one. Hence, going to example.com/posts will call the posts or example.com/comment/new will call comment_new. This routing can be customized by passing extra parameters to serve. The endpoints are method-agnostic, so you can use GET, POST, PUT, DELETE, etc., to access them.
  • Parameters: In the endpoints file, the request parameters are read by calling functions with type names. For instance, calling str("tag", optional: true) will read the tag parameter, ensure it's a string, and return its value or null if not present. Parameters can come as form data, JSON, cookies, or even headers. By default, GET parameters are not allowed (this could lead to CSRF vulnerabilities), but you can enable them by passing allow_get: true to serve.
  • Response: The response is a JSON object or array returned by the endpoint function. If the function doesn't return anything, the response will be {"success": true}. If a parameter validation fails or if a check is evaluated to false, it will serve a 400 error with {"error": }. If an uncaught exception is thrown, it will serve a 500 error.

To know more about the usage, check out the documentation and the examples.

Contributing

If you want to contribute, you can do so by forking the repository and creating a pull request. You should have a look at the file first to follow the same ethos and style. If you plan to add a new feature or extend existing functionality, please open an issue first to discuss it. Feel free to open an issue if you find a bug or have a suggestion.

Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.

-- Antoine de Saint-Exupéry

Why Oink?

Oink should feel like a pig in the mud: simple and comfortable, even though it's not the cleanest thing in the world. This library prioritizes development speed and simplicity over everything else, including best practices and standards. If you are looking for a highly customizable, modular, and scalable solution, you should look for a full-featured framework like Laravel, Symfony, or Lumen.

See more here.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

PHP

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言