Quickly create a restful style API project and API documentation automation with Beego

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

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`-- ----------------------------DROP TABLE IF EXISTS `app`;CREATE TABLE `app` (  `id` int(11) NOT NULL AUTO_INCREMENT,  `create_date` datetime NOT NULL,  `app_code` varchar(255) COLLATE utf8_unicode_ci NOT NULL,  `app_name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,  `publish_date` date DEFAULT NULL,  PRIMARY KEY (`id`),  UNIQUE KEY `app_code` (`app_code`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;-- ------------------------------ Records of app-- ----------------------------INSERT INTO `app` VALUES ('1', NOW(), '100000', '神庙逃亡', '2015-08-06');INSERT INTO `app` VALUES ('2', NOW(), '100001', '愤怒的小鸟', '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:123456@tcp(127.0.0.1:3306)/jeedev"

Iv. Automation of API documentation

>>cd ./jeedev-api>>bee generate docs>>bee run watchall true//访问 

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 download Swagger-ui, the contents of the Project Dist directory under the Swagger directory of the project, modify the default URL in Index.html is (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/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.