Introduction

Starting from version v2.0, the Server component of the framework provides an additional standardized router registration method, which is more suitable for scenarios that require team standardization and projects with higher business complexity. The specified router implements the following features:

  • Standardization of API design according to structured programming
  • Specification of API API method parameter style definitions
  • Simplified router registration and maintenance
  • Unified API return data format design
  • Ensures synchronized maintenance of code and API documentation
  • Automatic reception and validation of API parameter objects
  • Automatic generation of API documentation based on the standard OpenAPIv3 protocol
  • Automatic generation of SwaggerUI pages

Standard Router - 图1tip

Please note that specified router along with the original function, object, group routing methods are all registration methods supported by the framework’s HTTP Server component. They are designed to solve scenarios of standardized and automated API management and are more suitable for multi-person team collaboration. Other routing methods, especially the function and object registration methods of the framework’s v1 version, are also supported in the new version! Choose reasonably based on personal usage habits.

Documentation

📄️ Standard Router - ExampleSetting up and running a simple Hello service example using the GoFrame framework, highlighting the use of configuration files, route definitions, and automatic generation of SwaggerUI pages. Additionally, it explores issues such as generating API documentation, handling return middleware, and how to define standardized API paths, providing developers with a convenient method to generate and test APIs.

📄️ Standard Router - UsageDefine router methods, manage and register routers, and standardize request and response objects in the GoFrame framework. By using the grouped router’s Bind method and the basic BindHandler method, we can effectively manage routers. It also includes how to validate input data and use a unified post-middleware for data processing.

📄️ Standard Router - FAQHow to support multiple HTTP Method submissions for the same API under the strict routing of the GoFrame framework. When designing RESTful APIs, each API should correspond to a specific HTTP Method, such as creating a user or retrieving a user list, etc. If multiple HTTP Methods need to be supported for an API, it can be set through Meta tags. Additionally, learn how to use type aliasing to return array forms for the Data field in the Response structure.