使用 REST 公开 MySQL 数据库/表
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4771485/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Exposing MySQL database/table using REST
提问by aherlambang
What would be the easiest way to expose a MySQL database using a RESTinterface?
使用REST接口公开 MySQL 数据库的最简单方法是什么?
The only guidelines that I can find on the Internet is just using NetBeans. I am not a big fan of NetBeans...
我可以在 Internet 上找到的唯一指南就是使用NetBeans。我不是 NetBeans 的忠实粉丝...
I'd like to retrieve that and be able to update data on the database using this REST interface.
我想检索它并能够使用此 REST 接口更新数据库上的数据。
FYI, this is for an iPhone application that I am currently working on.
仅供参考,这是针对我目前正在开发的 iPhone 应用程序。
采纳答案by kander
As dorkitude commented, it depends on what languages you can use / want to use.
正如 dorkitude 评论的那样,这取决于您可以使用/想要使用的语言。
I found the project PHPRestSQL which seems to do what you want: http://phprestsql.sourceforge.net/- haven't tried it myself though.
我发现 PHPRestSQL 项目似乎可以满足您的需求:http://phprestsql.sourceforge.net/ - 不过我自己还没有尝试过。
回答by Mark Sawers
Another option is restSQL, an ultra-lightweight persistence framework. http://restsql.org. It supports MySQL and PostgreSQL and runs in a standard Java EE container, e.g. Apache Tomcat.
另一种选择是restSQL,一个超轻量级的持久化框架。http://restsql.org。它支持 MySQL 和 PostgreSQL,并在标准的 Java EE 容器中运行,例如 Apache Tomcat。
restSQL is a very unconventional data access layer. restSQL is not an object-oriented view of the database. It presents flat or hierarchical "views" of relational database tables. These views are query-able and updatable through a simple REST-based HTTP or Java API. The HTTP interface is based on REST principles, which use HTTP's built-in features, rather than abstracting away from them.
restSQL 是一个非常规的数据访问层。restSQL 不是数据库的面向对象视图。它呈现关系数据库表的平面或分层“视图”。这些视图可通过简单的基于 REST 的 HTTP 或 Java API 进行查询和更新。HTTP 接口基于 REST 原则,它使用 HTTP 的内置功能,而不是从它们中抽象出来。
回答by user3751385
MySQL 5.7.4 and above work with the HTTP plugin, which offers a HTTP REST API.
MySQL 5.7.4 及更高版本使用 HTTP 插件,该插件提供 HTTP REST API。
SQL: SELECT * FROM simple ORDER BY id
URL: http://127.0.0.1:8080/sql//SELECT+%2A+FROM+simple+ORDER+BY+id
However, it currently comes with a NOT FIT FOR PRODUCTIONwarning.
但是,它目前带有NOT FIT FOR PRODUCTION警告。
回答by mozboz
2017 Update:
2017年更新:
PHP: Another good player in the field is https://slimframework.com
PHP:该领域的另一个优秀参与者是https://slimframework.com
Python: http://python-eve.org/
For people finding this in 2015, potential solutions that are still working/under development as of Oct are:
对于在 2015 年发现这一点的人来说,截至 10 月仍在工作/正在开发的潜在解决方案是:
Haskell (binary): https://github.com/begriffs/postgrest
Haskell(二进制):https: //github.com/begriffs/postgrest
Java: http://restsql.org/
Java:http: //restsql.org/
回答by limc
回答by Sorter
My recommendation in 2020 would be using metamug console. Metamug console is language agnostic and builds APIs with a MySQL connection and no extra setup.
我在 2020 年的建议是使用metamug console。Metamug 控制台与语言无关,并使用 MySQL 连接构建 API,无需额外设置。
Resource Editor
资源编辑器
The console comes with a resource editor that helps you map requests to sql statements. You can add parameter validation and parameters into the queries.
控制台带有资源编辑器,可帮助您将请求映射到 sql 语句。您可以将参数验证和参数添加到查询中。
Documentation
文档
It generates resource documentation.
Other Features you may need.
您可能需要的其他功能。
- It can handle complex JSON requests along with multipart and URL-encoded data
- Implements standard status codes and error handling so you don't have to sweat.
- Comes with built-in query testing to fail fast development.
- Role-based per resource authentication.
- 它可以处理复杂的 JSON 请求以及多部分和 URL 编码的数据
- 实施标准状态代码和错误处理,因此您不必担心。
- 带有内置查询测试以失败快速开发。
- 基于角色的每个资源身份验证。
You can ask questions with metamug tag
您可以使用metamug 标签提问
Disclaimer: I'm part of the dev team. And we have been working on metamug console from last 3 years.
免责声明:我是开发团队的一员。从过去 3 年开始,我们一直在研究 metamug 控制台。
You can easily export the apis build with metamug console to be used in production and the exported webapp is built on top of open source mason library
您可以使用 metamug 控制台轻松导出 apis 构建以用于生产,并且导出的 webapp 构建在开源 mason 库之上
回答by saiy2k
Seems MySQL is getting REST interface natively, so we can query the DB, without a need for server... :-)
似乎 MySQL 正在本地获取 REST 接口,因此我们可以查询数据库,而无需服务器... :-)
回答by Mark Gavagan
Another option is Slash dbwhich "automatically generates a REST API from relational databases."
另一种选择是Slash db,它“从关系数据库自动生成 REST API”。
As of June 2017, it works for SQL databases without adjustment, but other kinds of data stores require a custom developed plugin.
截至 2017 年 6 月,它适用于 SQL 数据库,无需调整,但其他类型的数据存储需要自定义开发的插件。
I've only read about this service (not a user). I have no affiliation with them.
我只阅读了有关此服务的信息(不是用户)。我与他们没有任何关系。
回答by mevdschee
In 2019, you may use PHP-CRUD-API. It is a single file PHP script that adds a REST API to a MySQL 5.6 InnoDB database. PostgreSQL 9.1 and MS SQL Server 2012 are also fully supported.
2019 年,您可以使用PHP-CRUD-API。它是一个单文件 PHP 脚本,可将 REST API 添加到 MySQL 5.6 InnoDB 数据库。还完全支持 PostgreSQL 9.1 和 MS SQL Server 2012。
Disclaimer: I wrote it.
免责声明:我写的。
回答by npr
One of the easiest ways to create REST APIs for any MySql database is to use Xmysql
为任何 MySql 数据库创建 REST API 的最简单方法之一是使用Xmysql
- Xmysql with one command you can get literally thousands of APIs within seconds (based on num of tables).
- Xmysql not only generates CRUD but also some sophisticated aggregate APIs too.
- Xmysql has a really well written documentation that accompanies in the repo.
- There is docker support as well
- Xmysql 使用一个命令,您可以在几秒钟内获得数以千计的 API(基于表的数量)。
- Xmysql 不仅生成 CRUD,还生成一些复杂的聚合 API。
- Xmysql 在 repo 中有一个写得很好的文档。
- 还有 docker 支持