Quickly create a restful style API project and API documentation automation with Beego
This article demonstrates how to create a RESTful API project based on databases and tables quickly (within a minute, without writing a line of code), and to provide an interface that facilitates the online test API.
I. CREATE DATABASE and data table (MySQL)
#db--jeedev-- ------------------------------Table structure for ' app '-- ----------------------------DROPTABLEIFEXISTS' App ';CREATETABLE' App ' (' ID 'int11)NotNULL Auto_increment,' Create_date ' datetimeNotNull' App_Code 'varchar255)COLLATE Utf8_unicode_ciNotNull' App_name 'varchar255)COLLATE Utf8_unicode_ciNotNull' Publish_date 'DateDEFAULTNullPRIMARYKEY (' ID '),UNIQUEKEY' App_Code ' (' App_Code '))Engine=InnoDBDEFAULTCharset=utf8Collate=utf8_unicode_ci;-- ------------------------------Records of apps-- ----------------------------INSERTinto ' app ' VALUES ( ' 1 ', now (), ' 100000 ', ' temple escape ', 2015-08-06 '); insert INTO " app ' values ( ' 2 ', now (), 100001 ', ' Angry Birds ', 2015-08-06 ')
Ii. creating Golang and Beego Environment
- Official Documentation Guide Http://beego.me/quickstart
Iii. creating a RESTful style API project from a database
>>bee api jeedev-api -conn="root:[email protected](127.0.0.1:3306)/jeedev"
Iv. Automation of API documentation
>>cd ./jeedev-api>>bee generate docs>>bee run watchall true//访问 /127.0.0.1:8080/docs> 即可看到自动化生产的API文档
Integrated swagger UI, providing restful test interfaces and data online
The *swagger UI is a restful interface for document online automatic generation + functional test function software. Official website Http://swagger.io
5.1 Manually download swagger to the project directory
- Download the swagger package (https://github.com/beego/swagger/releases) provided by Beego to the project directory
- Or to the official address Https://github.com/swagger-api/swagger-ui download Swagger-ui, the project Dist directory to copy the contents of the project under the Swagger directory, Modify the default URL in index.html to (Http://127.0.0.1:8080/docs)
5.2 Visit Http://127.0.0.1:8080/swagger
Vi. code Examples
- This sample code is stored in the HTTPS://GITHUB.COM/HULIGONG1234/GO-STUDY/TREE/MASTER/DAY06/JEEDEV-API
Resources:
- Beego official documentation--api Automation documentation HTTP://BEEGO.ME/DOCS/ADVANTAGE/DOCS.MD
- Beego API development and automation documentation http://my.oschina.net/astaxie/blog/284072
- Video tutorial-beego one minute to create an API http://www.tudou.com/programs/view/aM7iKLlBlrU/
Quickly create a restful style API project and API document Automation with Beego (GO)