简体   繁体   English

从数据库模型快速构建REST API

[英]Building a REST API quickly from a Database model

I've designed my database diagram(11 entites) for my prototype application. 我为我的原型应用程序设计了数据库图表(11个entites)。 I need to have an REST API on top of this that will allow me to build a prototype android tablet application that talks to it. 我需要有一个REST API,这将允许我构建一个与它对话的原型Android平板电脑应用程序。

Considering this is only for prototype purposes. 考虑到这只是为了原型目的。 What would be the quickest way to get a API up and running that would allow me to get, put, delete etc.. 什么是最快的方式来启动和运行API,这将允许我获取,放置,删除等。

Security at this point isn't an issue so even if all add edit delete were open that would be fine. 此时的安全性不是问题所以即使所有添加编辑删除都是开放的也没关系。

My initial idea is to build this with PHP and MySQL maybe using the Yii framework to help but I feel there might be something that might be faster for my purpose. 我最初的想法是使用PHP和MySQL构建它可能使用Yii框架来帮助,但我觉得可能有一些东西可能更快我的目的。

Any thoughts or recommendations or advice? 有任何想法或建议或建议吗?

It is worth looking into API rapid-prototyping tools like Apify ( tutorial ) since you're starting from scratch. 因为你从头开始,所以值得研究API快速原型设计工具,如Apify教程 )。 If you're planning to have both an API and a Web site accessing the same data, consider using one framework for both as it helps prevent duplicating logic. 如果您计划同时使用API​​和Web站点访问相同的数据,请考虑为两者使用一个框架,因为它有助于防止重复逻辑。 CakePHP and Yii are good examples of multipurpose frameworks that are suited for this type of development. CakePHPYii是适合此类开发的多用途框架的很好的例子。

If Python is an option, it is trivial to use a light-weight http framework to build a REST API that accesses a database. 如果Python是一个选项,那么使用轻量级http框架来构建访问数据库的REST API是微不足道的。

Here's a snippet for a fully functioning http server using the itty framework: https://github.com/toastdriven/itty/blob/master/examples/web_service.py and https://github.com/toastdriven/itty/blob/master/examples/posting_data.py 这是使用itty框架的功能完备的http服务器的片段: https//github.com/toastdriven/itty/blob/master/examples/web_service.pyhttps://github.com/toastdriven/itty/blob/主/示例/ posting_data.py

Look at this project which allows you to create an API REST in seconds. 看看这个允许您在几秒钟内创建API REST的项目。

https://github.com/GeekyTheory/Automatic-API-REST https://github.com/GeekyTheory/Automatic-API-REST

Features 特征

  1. Creation a powerful API REST of your MySQL Data Base in Seconds. 以秒为单位创建MySQL数据库的强大API REST。
  2. Management of the API in situ, it is not neccesary an extra data base. 在原地管理API,它不是一个额外的数据库。
  3. Private tables and fields. 私人表格和字段。
  4. Custom queries. 自定义查询。

Installation 安装

  1. Clone the repo. 克隆回购。

    git clone https://github.com/GeekyTheory/Automatic-API-REST/ git clone https://github.com/GeekyTheory/Automatic-API-REST/

  2. Place it in your web folder /var/www/YourWebPage/ 将它放在您的web文件夹/var/www/YourWebPage/

  3. Open the file config.php and complete all the fields with the server credencials. 打开文件config.php并使用服务器credencials完成所有字段。
  4. Go to domain.com/AutomaticaApiRest 转到domain.com/AutomaticaApiRest

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM