oink.php 是一个单文件 PHP 库,可用于轻松构建 API。
oink.php is a free and open source API wrapper for PHP, in a single 7kB file.
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.
This minimal example shows how to create a simple blog API:
index.php
require_once 'oink.php';
Oink\serve('endpoints.php');endpoints.php
…Let's see what's happening here:
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.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.{"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.
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
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,或尚未同步最近议题。