### Setting Up and Running Local Development Server (Shell) Source: https://github.com/tencentblueking/blueking-apigateway/blob/master/src/dashboard/README.md Provides a sequence of shell commands to set up the Python environment, install dependencies, configure environment variables, run database migrations, and start the Django development server for local development. Remember to edit `apigateway/conf/.env` after copying. ```shell cd src/dashboard/apigateway pip install -r requirements.txt pip install -r requirements_dev.txt cp apigateway/conf/.env.tpl apigateway/conf/.env python manage.py migrate python manage.py migrate --database bkcore python manage.py runserver ``` -------------------------------- ### Starting BlueKing API Gateway Local Server (Go) Source: https://github.com/tencentblueking/blueking-apigateway/blob/master/src/dashboard/apigateway/apigateway/templates/dev_guideline/en/programmable_gateway.md This command starts the local development server for a Go-based BlueKing API Gateway project. After execution, the Swagger UI for API documentation can be accessed at `http://0.0.0.0:8080/swagger-ui/index.html`. ```bash go run main.go webserver ``` -------------------------------- ### Installing BlueKing API Gateway Go SDK Source: https://github.com/tencentblueking/blueking-apigateway/blob/master/src/dashboard/apigateway/apigateway/templates/api_sdk/en/golang_sdk_doc.md This command installs the latest version of the BlueKing API Gateway Go SDK core module using `go get`. It fetches the SDK from GitHub, making it available for use in Go projects. ```shell go get -u github.com/TencentBlueKing/bk-apigateway-sdks/core@latest ``` -------------------------------- ### Example Request Parameters for System Components API (Python) Source: https://github.com/tencentblueking/blueking-apigateway/blob/master/src/esb/esb/components/bk/apisv2/esb/apidocs/zh_hans/get_components.md This snippet provides an example of the request body for the API to get system components. It demonstrates how to pass authentication credentials (`bk_app_code`, `bk_app_secret`, `bk_token`) and the required `system_names` list, which specifies the systems for which components are to be retrieved. ```python { "bk_app_code": "esb_test", "bk_app_secret": "xxx", "bk_token": "xxx", "system_names": ["BK_LOGIN", "XXXX"] } ``` -------------------------------- ### Starting BlueKing API Gateway Local Server (Python) Source: https://github.com/tencentblueking/blueking-apigateway/blob/master/src/dashboard/apigateway/apigateway/templates/dev_guideline/en/programmable_gateway.md This command starts the local development server for a Python-based BlueKing API Gateway project. After execution, the Swagger UI for API documentation can be accessed at `http://0.0.0.0:8080/api/schema/swagger-ui/#/open`. ```bash python manage.py runserver 0.0.0.0:8080 ``` -------------------------------- ### Example Request Body for Getting Application Information - Python Source: https://github.com/tencentblueking/blueking-apigateway/blob/master/src/esb/esb/components/bk/apisv2/bk_paas/apidocs/zh_hans/get_app_info.md This snippet shows an example request body for the API to retrieve application information. It includes the `bk_app_code`, `bk_app_secret`, and `bk_token` for authentication, along with `target_app_code` to specify multiple application IDs separated by semicolons. ```python { "bk_app_code": "esb_test", "bk_app_secret": "xxx", "bk_token": "xxx", "target_app_code": "bk_test;esb_test" } ``` -------------------------------- ### Starting Local Development Server for Plugin Maintenance (Shell) Source: https://github.com/tencentblueking/blueking-apigateway/blob/master/src/dashboard/README.md Starts the Django development server, allowing access to the admin interface at `/backend/admin42/plugin/` for modifying plugin-related models. ```shell python manage.py runserver ``` -------------------------------- ### Example Request Parameters for User Information API (Python) Source: https://github.com/tencentblueking/blueking-apigateway/blob/master/src/esb/esb/components/bk/apisv2/bk_login/apidocs/zh_hans/get_all_users.md This snippet shows an example of the request body for the API to retrieve all user information. It includes common application authentication parameters and an optional 'bk_role' parameter to filter users by their role. ```python { "bk_app_code": "esb_test", "bk_app_secret": "xxx", "bk_token": "xxx", "bk_role": 0 } ``` -------------------------------- ### Generating Edition Modules (Shell) Source: https://github.com/tencentblueking/blueking-apigateway/blob/master/src/dashboard/README.md Creates `__init__.pyi` files in new directories within the `editions` folder, ensuring mypy operates correctly for multi-version setups. ```shell make edition-modules ``` -------------------------------- ### Installing BlueKing API Gateway Python SDK Source: https://github.com/tencentblueking/blueking-apigateway/blob/master/src/dashboard/apigateway/apigateway/templates/esb_sdk/en/python_sdk_doc.md This command demonstrates how to install the BlueKing API Gateway Python SDK using pip. Users should replace `{component SDK package name}` with the actual name of the SDK package they intend to install. ```bash pip install {component SDK package name} ``` -------------------------------- ### Example Response Body for Getting Application Information - Python Source: https://github.com/tencentblueking/blueking-apigateway/blob/master/src/esb/esb/components/bk/apisv2/bk_paas/apidocs/zh_hans/get_app_info.md This snippet illustrates a successful response from the API for retrieving application information. It includes a `result` flag, `code` for status, `message`, and a `data` array containing objects with `bk_app_code` and `bk_app_name` for each retrieved application. ```python { "result": true, "code": 0, "message": "", "data": [ { "bk_app_code": "bk_test", "bk_app_name": "BKTest" }, { "bk_app_code": "esb_test", "bk_app_name": "ESBTest" } ] } ``` -------------------------------- ### Example Request Parameters for User Role API (Python) Source: https://github.com/tencentblueking/blueking-apigateway/blob/master/src/esb/esb/components/bk/apisv2/bk_login/apidocs/en/get_batch_users_platform_role.md This snippet provides an example of the JSON payload required for the API request to get user roles. It includes the application code, secret, an optional login token, and a list of usernames for which roles are to be retrieved. ```Python { "bk_app_code": "esb_test", "bk_app_secret": "xxx", "bk_token": "xxx", "bk_username_list": ["admin", "test"] } ``` -------------------------------- ### Importing Resource Documentation via SDK (Python) Source: https://github.com/tencentblueking/blueking-apigateway/blob/master/src/dashboard/apigateway/apigateway/data/apidocs/zh/import_resource_docs_by_swagger.md This Python SDK example demonstrates how to use the bkapi.bk_apigateway client to import resource documentation. It shows how to get the client and make the import_resource_docs_by_swagger call with the required parameters. ```python from bkapi.bk_apigateway.shortcuts import get_client_by_request client = get_client_by_request(request) result = client.api.import_resource_docs_by_swagger( { "language": "zh", "swagger": "xxx" } ) ``` -------------------------------- ### Example Response for System Components API (Python) Source: https://github.com/tencentblueking/blueking-apigateway/blob/master/src/esb/esb/components/bk/apisv2/esb/apidocs/zh_hans/get_components.md This snippet illustrates a successful response from the API, showing the structure of the returned data. The `data` field contains a list of component objects, each detailing properties like `name`, `label`, `version`, `method`, `path`, `system_id`, `system_name`, `type`, and `category`. ```python { "result": true, "code": 0, "data": [ { "name": "get_all_users", "label": "获取所有用户信息", "version": "v2", "method": "GET", "path": "/api/c/compapi/v2/bk_login/get_all_users/", "system_id": 1, "system_name": "BK_LOGIN", "type": 2, "category": "component" }, { "name": "get_api_check_component_exist", "label": "check_component_exist", "version": "", "method": "GET", "path": "/api/c/self-service-api/api/check_component_exist/", "system_id": 6, "system_name": "XXXX", "type": 2, "category": "buffet_component" } ], "message": "" } ``` -------------------------------- ### Installing BlueKing API Gateway Python SDK Source: https://github.com/tencentblueking/blueking-apigateway/blob/master/src/dashboard/apigateway/apigateway/templates/api_sdk/en/python_sdk_doc.md This command demonstrates how to install the BlueKing API Gateway Python SDK using pip. Users should replace `{gateway SDK package name}` with the actual name of the SDK package. ```Shell pip install {gateway SDK package name} ``` -------------------------------- ### Example Request Parameters for ESB System List (Python) Source: https://github.com/tencentblueking/blueking-apigateway/blob/master/src/esb/esb/components/bk/apisv2/esb/apidocs/en/get_systems.md This snippet provides an example of the request parameters required to retrieve the list of systems accessing the ESB. It includes standard authentication parameters like `bk_app_code`, `bk_app_secret`, and `bk_token`. ```JSON { "bk_app_code": "esb_test", "bk_app_secret": "xxx", "bk_token": "xxx" } ``` -------------------------------- ### Example Request Parameters for User Information API (Python) Source: https://github.com/tencentblueking/blueking-apigateway/blob/master/src/esb/esb/components/bk/apisv2/bk_login/apidocs/zh_hans/get_user.md This snippet shows an example of the request body parameters required to call the user information API. It includes the application code (`bk_app_code`), application secret (`bk_app_secret`), and user token (`bk_token`) for authentication purposes. ```python { "bk_app_code": "esb_test", "bk_app_secret": "xxx", "bk_token": "xxx" } ``` -------------------------------- ### Example Request Parameters for Creating Light Application - Python Source: https://github.com/tencentblueking/blueking-apigateway/blob/master/src/esb/esb/components/bk/apisv2/bk_paas/apidocs/en/create_app.md This snippet provides an example of the JSON payload required to create a light application. It includes essential fields like application code, secret, token, name, URL, developer, and optional display dimensions. ```python { "bk_app_code": "gcloud", "bk_app_secret": "xxx", "bk_token": "xxx", "bk_light_app_name": "轻应用测试", "app_url": "http://test.bking.com/o/gcloud/xxx/", "developer": "test1;test2", "introduction": "introduction", "width": 1024, "height": 768 } ``` -------------------------------- ### Example Request Parameters for Host Info API - Python Source: https://github.com/tencentblueking/blueking-apigateway/blob/master/src/esb/esb/components/bk/apisv2/cc/apidocs/en/get_host_base_info.md This snippet provides an example of the JSON payload used to request host base information. It includes the application code, secret, token for authentication, an optional supplier account, and the required host ID. ```python { "bk_app_code": "esb_test", "bk_app_secret": "xxx", "bk_token": "xxx", "bk_supplier_account": "123456789", "bk_host_id": 10000 } ``` -------------------------------- ### Example Response for User Information API (Python) Source: https://github.com/tencentblueking/blueking-apigateway/blob/master/src/esb/esb/components/bk/apisv2/bk_login/apidocs/zh_hans/get_all_users.md This snippet illustrates a successful response from the API for retrieving all user information. It includes a 'data' array containing a list of user objects, each with details like username, QQ, phone, email, and role. ```python { "result": true, "code": 0, "message": "OK", "data": [ { "bk_username": "admin", "qq": "12345", "bk_role": 0, "language": "zh-cn", "phone": "12345678911", "wx_userid": "", "email": "11@qq.com", "chname": "admin", "time_zone": "Asia/Shanghai" } ] } ``` -------------------------------- ### Example Request Parameters for Component List API - Python Source: https://github.com/tencentblueking/blueking-apigateway/blob/master/src/esb/esb/components/bk/apisv2/esb/apidocs/en/get_components.md This Python dictionary illustrates the required parameters for the API call to get component lists. It includes authentication credentials ("bk_app_code", "bk_app_secret", "bk_token") and a list of system names ("system_names") for which components are to be retrieved. The "system_names" field is mandatory and can be populated using the component get_systems. ```Python { "bk_app_code": "esb_test", "bk_app_secret": "xxx", "bk_token": "xxx", "system_names": ["BK_LOGIN", "XXXX"] } ``` -------------------------------- ### Request Parameters Example for Resource Documentation Import (JSON) Source: https://github.com/tencentblueking/blueking-apigateway/blob/master/src/dashboard/apigateway/apigateway/data/apidocs/zh/import_resource_docs_by_swagger.md This JSON snippet provides an example of the request body structure required when importing resource documentation. It specifies the documentation language and the Swagger content. ```json { "language": "zh", "swagger": "xxx" } ``` -------------------------------- ### Example Request for Querying Business Information (Python) Source: https://github.com/tencentblueking/blueking-apigateway/blob/master/src/esb/esb/components/bk/apisv2/cc/apidocs/zh_hans/search_business.md This snippet demonstrates the structure of a request body for querying business information via the API. It includes authentication details, optional fields to retrieve, conditions for filtering results (e.g., by business name), and pagination settings like start, limit, and sort order. It illustrates how to specify which fields to return and how to apply filters. ```python { "bk_app_code": "esb_test", "bk_app_secret": "xxx", "bk_token": "xxx", "bk_supplier_account": "123456789", "fields": [ "bk_biz_id", "bk_biz_name" ], "condition": { "bk_biz_name": "esb-test" }, "page": { "start": 0, "limit": 10, "sort": "" } } ``` -------------------------------- ### Installing BlueKing API Gateway SDK with Maven Source: https://github.com/tencentblueking/blueking-apigateway/blob/master/src/dashboard/apigateway/apigateway/templates/api_sdk/en/java_sdk_doc.md This snippet shows how to add the BlueKing API Gateway SDK as a dependency in a Maven project's pom.xml file. Replace {gateway_name} with the specific gateway artifact ID and {sdk_version} with the desired SDK version. ```XML com.tencent.bkapi {gateway_name} {sdk_version} ``` -------------------------------- ### Example Request Parameters for ESB Component List - Python Source: https://github.com/tencentblueking/blueking-apigateway/blob/master/src/esb/esb/components/bk/apisv2/esb/apidocs/zh_hans/get_systems.md This snippet shows an example of the request parameters required to query the ESB component system list. It includes the application code (bk_app_code), application secret (bk_app_secret), and user token (bk_token) for authentication. ```python { "bk_app_code": "esb_test", "bk_app_secret": "xxx", "bk_token": "xxx" } ``` -------------------------------- ### Example Request Parameters for Application Info API - Python Source: https://github.com/tencentblueking/blueking-apigateway/blob/master/src/esb/esb/components/bk/apisv2/bk_paas/apidocs/en/get_app_info.md This snippet demonstrates the structure of the request body for the application information API. It includes common authentication fields and the 'target_app_code' parameter, which allows specifying multiple application IDs separated by semicolons. ```python { "bk_app_code": "esb_test", "bk_app_secret": "xxx", "bk_token": "xxx", "target_app_code": "bk_test;esb_test" } ``` -------------------------------- ### Example Response for Batch User Role API - Python Source: https://github.com/tencentblueking/blueking-apigateway/blob/master/src/esb/esb/components/bk/apisv2/bk_login/apidocs/zh_hans/get_batch_users_platform_role.md This snippet illustrates the structure of a successful response from the API. It indicates success with a 'result' flag, a 'code' of 0, a 'message' of 'OK', and a 'data' object containing user roles categorized by product, such as 'bkdata' and 'job'. ```python { "result": true, "code": 0, "message": "OK", "data": { "admin": { "bkdata": [ 1 ], "job": [ 2 ] } } } ``` -------------------------------- ### Example Request Parameters for Resource Version Query (JSON) Source: https://github.com/tencentblueking/blueking-apigateway/blob/master/src/dashboard/apigateway/apigateway/data/apidocs/zh/list_resource_versions.md This JSON snippet provides an example of the request body for querying resource versions. It includes optional parameters like 'version' for a specific version, 'limit' to control the number of returned items, and 'offset' for pagination. ```json { "version": "1.0.0", "limit": 10, "offset": 0 } ``` -------------------------------- ### Installing BlueKing API Gateway SDK with Gradle Source: https://github.com/tencentblueking/blueking-apigateway/blob/master/src/dashboard/apigateway/apigateway/templates/api_sdk/en/java_sdk_doc.md This snippet demonstrates how to declare the BlueKing API Gateway SDK as an implementation dependency in a Gradle project's build.gradle file. Replace {gateway_name} with the specific gateway artifact ID and {sdk_version} with the desired SDK version. ```Groovy implementation 'com.tencent.bkapi:{gateway_name}:{sdk_version}' ``` -------------------------------- ### Building and Running Core API (Bash) Source: https://github.com/tencentblueking/blueking-apigateway/blob/master/src/core-api/README.md This snippet provides a sequence of `make` commands to initialize development tools, download vendor dependencies, build the project, and finally serve the application. It outlines the standard process for setting up and running the core-api project locally. ```bash # install tools make init # download vendor make dep # build make build # build and serve make serve ``` -------------------------------- ### Example Request Parameters for Add Host API - Python Source: https://github.com/tencentblueking/blueking-apigateway/blob/master/src/esb/esb/components/bk/apisv2/cc/apidocs/en/add_host_to_resource.md This snippet provides an example of the JSON payload required to add a host to a resource. It demonstrates the structure for `bk_app_code`, `bk_app_secret`, `bk_token`, `bk_supplier_account`, and the nested `host_info` dictionary with `bk_host_innerip`, `bk_cloud_id`, and `import_from`. ```python { "bk_app_code": "esb_test", "bk_app_secret": "xxx", "bk_token": "xxx", "bk_supplier_account": "123456789", "host_info": { "0": { "bk_host_innerip": "1.0.0.1", "bk_cloud_id": 0, "import_from": "3" } } } ``` -------------------------------- ### Example Request Parameters for Module Search - JSON Source: https://github.com/tencentblueking/blueking-apigateway/blob/master/src/esb/esb/components/bk/apisv2/cc/apidocs/en/search_module.md This JSON snippet provides an example of the request body required to search for modules. It includes common application credentials, business ID, fields to retrieve, search conditions for module name, and pagination settings. ```json { "bk_app_code": "esb_test", "bk_app_secret": "xxx", "bk_token": "xxx", "bk_supplier_account": "123456789", "bk_biz_id": 2, "fields": [ "bk_module_name", "bk_set_id" ], "condition": { "bk_module_name": "test" }, "page": { "start": 0, "limit": 10 } } ``` -------------------------------- ### Initializing BlueKing API Gateway Project (Go) Source: https://github.com/tencentblueking/blueking-apigateway/blob/master/src/dashboard/apigateway/apigateway/templates/dev_guideline/en/programmable_gateway.md This snippet provides commands to initialize a new Go-based BlueKing API Gateway project. For the Enterprise Edition (EE), it uses `cookiecutter` to scaffold the project from a GitHub template, followed by standard Git initialization steps. For other editions, it suggests a simple `git clone`. ```bash {% if edition == "ee" %} pip install cookiecutter cookiecutter https://github.com/TencentBlueKing/bk-apigateway-framework/ --directory templates/golang project_name: {{project_name}} init_admin: {{init_admin}} cd {{project_name}} git init git add . git commit -m "init project" git remote add origin {{repo_url}} # Replace with the actual repository URL git push -u origin master {% else %} git clone {{repo_url}} {% endif %} ``` -------------------------------- ### Example Request Payload for Creating Module - Python Source: https://github.com/tencentblueking/blueking-apigateway/blob/master/src/esb/esb/components/bk/apisv2/cc/apidocs/en/create_module.md This snippet provides an example of the JSON payload required to create a new module. It includes authentication details, supplier account, business and set IDs, and the module-specific data such as parent ID and module name. ```python { "bk_app_code": "esb_test", "bk_app_secret": "xxx", "bk_token": "xxx", "bk_supplier_account": "123456789", "bk_biz_id": 1, "bk_set_id": 10, "data": { "bk_parent_id": 10, "bk_module_name": "test" } } ``` -------------------------------- ### Example Request Payload for New Business API (Python) Source: https://github.com/tencentblueking/blueking-apigateway/blob/master/src/esb/esb/components/bk/apisv2/cc/apidocs/en/create_business.md This snippet provides an example of the JSON payload required to create a new business via the API. It includes common authentication parameters and specific business details such as name, maintainers, time zone, and language. ```python { "bk_app_code": "esb_test", "bk_app_secret": "xxx", "bk_token": "xxx", "bk_supplier_account": "123456789", "data": { "bk_biz_name": "cc_app_test", "bk_biz_maintainer": "admin", "bk_biz_productor": "admin", "bk_biz_developer": "admin", "bk_biz_tester": "admin", "time_zone": "Asia/Shanghai", "language": "1" } } ``` -------------------------------- ### Example Request Parameters for User Retrieval - Python Source: https://github.com/tencentblueking/blueking-apigateway/blob/master/src/esb/esb/components/bk/apisv2/bk_login/apidocs/en/get_user.md This snippet provides an example of the request parameters required to retrieve user information from the BlueKing API Gateway. It includes authentication credentials such as 'bk_app_code', 'bk_app_secret', and 'bk_token', which are essential for API access. ```Python { "bk_app_code": "esb_test", "bk_app_secret": "xxx", "bk_token": "xxx" } ``` -------------------------------- ### Example Request Body for Getting Custom Query Details (Python) Source: https://github.com/tencentblueking/blueking-apigateway/blob/master/src/esb/esb/components/bk/apisv2/cc/apidocs/zh_hans/get_custom_query_detail.md This snippet shows an example JSON payload for the API request to retrieve custom query details. It includes common authentication parameters and specific query parameters like 'bk_supplier_account', 'bk_biz_id', and 'id'. ```python { "bk_app_code": "esb_test", "bk_app_secret": "xxx", "bk_token": "xxx", "bk_supplier_account": "123456789", "bk_biz_id": 1, "id": "xxx" } ``` -------------------------------- ### Example Request Parameters for Business Topology Query - Python Source: https://github.com/tencentblueking/blueking-apigateway/blob/master/src/esb/esb/components/bk/apisv2/cc/apidocs/zh_hans/search_biz_inst_topo.md This snippet provides an example of the JSON payload used to query business instance topology. It includes common application credentials such as `bk_app_code`, `bk_app_secret`, and `bk_token`, along with specific parameters like `bk_supplier_account` for the developer and `bk_biz_id` for the target business. ```python { "bk_app_code": "esb_test", "bk_app_secret": "xxx", "bk_token": "xxx", "bk_supplier_account": "123456789", "bk_biz_id": 1 } ``` -------------------------------- ### API Gateway Request Body Example (JSON) Source: https://github.com/tencentblueking/blueking-apigateway/blob/master/src/dashboard/apigateway/apigateway/data/apidocs/zh/get_stages_with_resource_version.md This JSON snippet provides an example of the request body for the API call. It shows an empty object, indicating that no specific parameters are required in the request body for this operation. ```json {} ``` -------------------------------- ### Example Request Parameters for Host Allocation API - Python Source: https://github.com/tencentblueking/blueking-apigateway/blob/master/src/esb/esb/components/bk/apisv2/cc/apidocs/zh_hans/transfer_resourcehost_to_idlemodule.md This snippet provides an example JSON payload for the host allocation API. It demonstrates the structure for `bk_app_code`, `bk_app_secret`, `bk_token`, `bk_supplier_account`, `bk_biz_id`, and `bk_host_id`, showing how to pass multiple host IDs in an array. ```python { "bk_app_code": "esb_test", "bk_app_secret": "xxx", "bk_token": "xxx", "bk_supplier_account": "123456789", "bk_biz_id": 1, "bk_host_id": [ 9, 10 ] } ``` -------------------------------- ### Example Request Parameters for Creating Module - Python Source: https://github.com/tencentblueking/blueking-apigateway/blob/master/src/esb/esb/components/bk/apisv2/cc/apidocs/zh_hans/create_module.md This snippet provides an example of the JSON payload required to create a module. It includes common authentication parameters and specific module creation data such as `bk_biz_id`, `bk_set_id`, `bk_parent_id`, and `bk_module_name`. ```python { "bk_app_code": "esb_test", "bk_app_secret": "xxx", "bk_token": "xxx", "bk_supplier_account": "123456789", "bk_biz_id": 1, "bk_set_id": 10, "data": { "bk_parent_id": 10, "bk_module_name": "test" } } ``` -------------------------------- ### Initializing BlueKing API Gateway Project (Python) Source: https://github.com/tencentblueking/blueking-apigateway/blob/master/src/dashboard/apigateway/apigateway/templates/dev_guideline/en/programmable_gateway.md This snippet provides commands to initialize a new BlueKing API Gateway project. For the Enterprise Edition (EE), it uses `cookiecutter` to scaffold the project from a GitHub template, followed by standard Git initialization steps. For other editions, it suggests a simple `git clone`. ```bash {% if edition == "ee" %} pip install cookiecutter cookiecutter https://github.com/TencentBlueKing/bk-apigateway-framework/ --directory templates/python project_name: {{project_name}} init_admin: {{init_admin}} cd {{project_name}} git init git add . git commit -m "init project" git remote add origin {{repo_url}} # Please replace with the actual repository address git push -u origin master {% else %} git clone {{repo_url}} {% endif %} ``` -------------------------------- ### Initializing Client and Calling API Operation in Go Source: https://github.com/tencentblueking/blueking-apigateway/blob/master/src/dashboard/apigateway/apigateway/templates/api_sdk/en/golang_sdk_usage_example_bkapi.md This snippet demonstrates how to initialize a `bkapi` client, define request and response structures, create an API operation with various parameters (headers, path, query, body), and execute the API call. It showcases setting general client configurations like request headers and declaring JSON providers for requests and responses. ```Go package demo import ( "fmt" "log" "github.com/TencentBlueKing/bk-apigateway-sdks/core/bkapi" "github.com/TencentBlueKing/bk-apigateway-sdks/core/define" ) type QueryUserDemoBodyRequest struct { Name string `json:"name"` Age int `json:"age"` } type QueryUserDemoResponse struct { Name string `json:"name"` Age int `json:"age"` Address string `json:"address"` Gender string `json:"gender"` } func clientExample() { // Initialize the client client, err := bkapi.NewBkApiClient("demo", bkapi.ClientConfig{ Endpoint: "http://special-api.example.com/prod", // a specific gateway address ClientOptions: []define.BkApiClientOption{ // Set some general client configuration, eg. bkapi.OptSetRequestHeader("X-Api-Key", "123456"), // set the uniform header bkapi.OptJsonResultProvider(), // Declare all responses from this gateway to be JSON bkapi.OptJsonBodyProvider(), // Declare that all body requests from this gateway are JSON. }, }) if err != nil { log.Printf("client init error: %v", err) } // Create the api operation apiOperation := client.NewOperation( // Fill in the interface configuration bkapi.OperationConfig{ Name: "query_team_user_demo", Method: "GET", Path: "/get/{team_id}/user/", }, // Set the header parameter bkapi.OptSetRequestHeader("X-Bkapi-Header", "demo"), // Set the path parameter bkapi.OptSetRequestPathParams( map[string]string{ "team_id": "1", // Set the path parameters. }, ), // Set the query parameters bkapi.OptSetRequestQueryParam("name", "demo"), // Set the body parameter: custom struct bkapi.OptSetRequestBody(QueryUserDemoBodyRequest{Name: "demo"}), // Set the body parameter: map[string]string bkapi.OptSetRequestBody(map[string]string{"name": "demo"}), ) // Create the result variable var result QueryUserDemoResponse // Call the interface (Request() returns: *http.Response,err, depending on the case if it needs to be handled) //// pass the parameter directly through the api operation //_,_=apiOperation.SetHeaders(map[string]string{"X-Bkapi-Header": "demo"}). // SetPathParams(map[string]string{"team_id": "1"}). // SetBody(QueryUserDemoBodyRequest{Name: "demo"}). // SetQueryParams(map[string]string{"name": "demo"}). // SetResult(&result).Request() //_, _ = client.StatusCode(bkapi.OptSetRequestQueryParams(map[string]string{ // "code": "200", //})).SetResult(&result).Request() _, _ = apiOperation.SetResult(&result).Request() // The result will be automatically populated into result fmt.Printf("%#v", result) } ``` -------------------------------- ### Example Nginx Reverse Proxy Configuration Source: https://github.com/tencentblueking/blueking-apigateway/blob/master/src/dashboard/README.md An example Nginx server block configuration for reverse proxying, directing root requests to a frontend server on port 8888 and `/backend/` requests to a backend server on port 8000. ```nginx server { listen 80; server_name dev-apigw.example.com; location / { proxy_pass http://127.0.0.1:8888; } location /backend/ { proxy_pass http://127.0.0.1:8000; } } ``` -------------------------------- ### Using ClientConfigRegistry for Gateway Client Initialization in Go Source: https://github.com/tencentblueking/blueking-apigateway/blob/master/src/dashboard/apigateway/apigateway/templates/api_sdk/zh-hans/golang_sdk_usage_example_bkapi.md This snippet demonstrates two ways to use `bkapi.ClientConfigRegistry` to simplify client initialization. It shows how to register a default configuration that applies to all gateways or register specific configurations for individual gateways, reducing repetitive setup for `BkApiClient` instances. ```Go // 通过ClientConfigRegistry初始化client // 使用默认的全局的配置中心来初始化 registry: = bkapi.GetGlobalClientConfigRegistry() // 方式一:注册默认的配置(不区分网关) err: = registry.RegisterDefaultConfig(bkapi.ClientConfig { BkApiUrlTmpl: "http://{api_name}.example.com/", //网关通用地址 Stage: "prod", }) if err != nil { log.Printf("registry default config error: %v", err) return } // 使用默认的配置,在创建client的时候再指定网关 client, err: = bkapi.NewBkApiClient("my-gateway", registry) if err != nil { log.Fatalf("create bkapi client error: %v", err) return } // 方式二:注册指定的网关配置 err = registry.RegisterClientConfig("my-gateway", bkapi.ClientConfig { Endpoint: "http://special-api.example.com/prod", // 具体某个网关地址 ClientOptions: [] define.BkApiClientOption { // 设置一些通用的client配置,eg: bkapi.OptSetRequestHeader("X-Api-Key", "123456"), // 设置统一的header bkapi.OptJsonResultProvider(), // 声明这个网关的所有响应都是JSON bkapi.OptJsonBodyProvider(), // 声明这个网关的body请求都是JSON }, }) if err != nil { log.Fatalf("set bkapi client config error: %v", err) return } client, err = bkapi.NewBkApiClient("my-gateway", registry) if err != nil { log.Fatalf("create bkapi client error: %v", err) return } ``` -------------------------------- ### Creating and Calling an API Operation in Go Source: https://github.com/tencentblueking/blueking-apigateway/blob/master/src/dashboard/apigateway/apigateway/templates/api_sdk/en/golang_sdk_usage_example_bkapi.md This Go snippet demonstrates how to create an API operation using `client.NewOperation` with various configuration options like name, method, path, headers, path parameters, query parameters, and body. It also shows how to execute the operation and automatically populate the response into a result variable. ```golang // Create the api operation apiOperation := client.NewOperation( // Fill in the interface configuration bkapi.OperationConfig{ Name: "query_team_user_demo", Method: "GET", Path: "/get/{team_id}/user/", }, // Set the header parameter bkapi.OptSetRequestHeader("X-Bkapi-Header", "demo"), // Set the path parameter bkapi.OptSetRequestPathParams( map[string]string{ "team_id": "1" }, ), // Set the query parameters bkapi.OptSetRequestQueryParam("name", "demo"), // Set the body parameter: custom struct bkapi.OptSetRequestBody(QueryUserDemoBodyRequest{Name: "demo"}), // Set the body parameter: map[string]string bkapi.OptSetRequestBody(map[string]string{"name": "demo"}), ) // Create the result variable var result QueryUserDemoResponse // Call the interface (Request() returns: *http.Response,err, depending on the case if it needs to be handled) //// pass the parameter directly through the api operation //_,_=apiOperation.SetHeaders(map[string]string{"X-Bkapi-Header": "demo"}). // SetPathParams(map[string]string{"team_id": "1"}). // SetBody(QueryUserDemoBodyRequest{Name: "demo"}). // SetQueryParams(map[string]string{"name": "demo"}). // SetResult(&result).Request() _, _ = apiOperation.SetResult(&result).Request() // The result will be automatically populated into result fmt.Printf("%#v", result) ``` -------------------------------- ### Initializing Client and Calling API Operation in Go Source: https://github.com/tencentblueking/blueking-apigateway/blob/master/src/dashboard/apigateway/apigateway/templates/api_sdk/zh-hans/golang_sdk_usage_example_bkapi.md This snippet demonstrates how to initialize a `bkapi.BkApiClient` with common configurations like endpoint, request headers, and JSON providers. It then shows how to create an `Operation` for a specific API resource, setting various parameters such as path, query, and body, and finally executing the request to populate a result struct. ```Go package demo import ( "fmt" "log" "github.com/TencentBlueKing/bk-apigateway-sdks/core/bkapi" "github.com/TencentBlueKing/bk-apigateway-sdks/core/define" ) type QueryUserDemoBodyRequest struct { Name string `json:"name"` Age int `json:"age"` } type QueryUserDemoResponse struct { Name string `json:"name"` Age int `json:"age"` Address string `json:"address"` Gender string `json:"gender"` } func clientExample() { // 初始化client client, err := bkapi.NewBkApiClient("demo", bkapi.ClientConfig{ Endpoint: "http://special-api.example.com/prod",// 具体某个网关地址 ClientOptions: []define.BkApiClientOption{ // 设置一些通用的client配置,eg: bkapi.OptSetRequestHeader("X-Api-Key", "123456"),// 设置统一的header bkapi.OptJsonResultProvider(),// 声明这个网关的所有响应都是JSON bkapi.OptJsonBodyProvider(), // 声明这个网关的body请求都是JSON }, }) if err != nil { log.Printf("client init error: %v", err) return } // 创建 api operation apiOperation := client.NewOperation( // 填充接口配置 bkapi.OperationConfig{ Name: "query_team_user_demo", Method: "GET", Path: "/get/{team_id}/user/", }, // 设置header参数 bkapi.OptSetRequestHeader("X-Bkapi-Header", "demo"), // 设置path参数 bkapi.OptSetRequestPathParams( map[string]string{ "team_id": `1`, }, ), // 设置query参数 bkapi.OptSetRequestQueryParam("name", "demo"), // 设置body参数: 自定义struct bkapi.OptSetRequestBody(QueryUserDemoBodyRequest{Name: "demo"}), // 设置body参数: map[string]string bkapi.OptSetRequestBody(map[string]string{"name": "demo"}), ) // 创建结果变量 var result QueryUserDemoResponse // 调用接口(Request()的返回值是:*http.Response,err,看具体情况是否需要处理) //// 直接通过 api operation传参 //_,_=apiOperation.SetHeaders(map[string]string{"X-Bkapi-Header": "demo"}). // SetPathParams(map[string]string{"team_id": `1`}). // SetBody(QueryUserDemoBodyRequest{Name: "demo"}). // SetQueryParams(map[string]string{"name": "demo"}). // SetResult(&result).Request() //_, _ = client.StatusCode(bkapi.OptSetRequestQueryParams(map[string]string{ // "code": `200`, //})).SetResult(&result).Request() _, _ = apiOperation.SetResult(&result).Request() // 结果将自动填充到 result 中 fmt.Printf("%#v", result) } ``` -------------------------------- ### Example Request Parameters for Editing Light Application - Python Source: https://github.com/tencentblueking/blueking-apigateway/blob/master/src/esb/esb/components/bk/apisv2/bk_paas/apidocs/zh_hans/edit_app.md This snippet provides an example of the JSON payload used when making a request to edit a light application. It includes required common arguments and specific light application details like `bk_light_app_code`, `bk_light_app_name`, `app_url`, `developer`, `introduction`, `width`, and `height`. ```python { "bk_app_code": "gcloud", "bk_app_secret": "xxx", "bk_token": "xxx", "bk_light_app_code": "gcloud_fdfh2kl0k", "bk_light_app_name": "轻应用测试", "app_url": "http://test.bking.com/o/gcloud/xxx/", "developer": "test1;test2", "introduction": "introduction", "width": 1024, "height": 768 } ``` -------------------------------- ### Example Request Parameters for Host Transfer API - Python Source: https://github.com/tencentblueking/blueking-apigateway/blob/master/src/esb/esb/components/bk/apisv2/cc/apidocs/en/transfer_host_to_idlemodule.md This snippet shows an example JSON payload for the API request to transfer hosts to an idle module. It includes application credentials, a supplier account, business ID, and a list of host IDs to be moved. ```python { "bk_app_code": "esb_test", "bk_app_secret": "xxx", "bk_token": "xxx", "bk_supplier_account": "123456789", "bk_biz_id": 1, "bk_host_id": [ 9, 10 ] } ``` -------------------------------- ### Registering Default Client Configuration with Registry in Go Source: https://github.com/tencentblueking/blueking-apigateway/blob/master/src/dashboard/apigateway/apigateway/templates/api_sdk/en/golang_sdk_usage_example_bkapi.md This snippet demonstrates how to register a default client configuration with the `ClientConfigRegistry` in Go. It sets a generic gateway URL template and stage, allowing clients to be initialized later by only specifying the gateway name, simplifying repetitive configuration tasks. ```Go // Initialize the client through the ClientConfigRegistry. // Initialize the client using the default global configuration center registry := bkapi.GetGlobalClientConfigRegistry() // Way 1: register the default configuration (regardless of gateway) err := registry.RegisterDefaultConfig(bkapi.ClientConfig { BkApiUrlTmpl: "http://{api_name}.example.com/", // gateway generic address Stage: "prod", }) if err != nil { log.Printf("registry default config error: %v", err) } // Use the default configuration and specify the gateway when creating the client client, err := bkapi.NewBkApiClient("my-gateway", registry) if err != nil { log.Fatalf("create bkapi client error: %v", err) return } ``` -------------------------------- ### Example Request Parameters for Data Query (Python) Source: https://github.com/tencentblueking/blueking-apigateway/blob/master/src/esb/esb/components/bk/apisv2/cc/apidocs/zh_hans/get_custom_query_data.md This snippet provides an example of the JSON payload used in a request to query data. It demonstrates the structure for common authentication parameters (`bk_app_code`, `bk_app_secret`, `bk_token`) along with specific query parameters like `bk_supplier_account`, `bk_biz_id`, `id`, `start`, and `limit`. ```python { "bk_app_code": "esb_test", "bk_app_secret": "xxx", "bk_token": "xxx", "bk_supplier_account": "123456789", "bk_biz_id": 1, "id": "xxx", "start": 0, "limit": 10 } ``` -------------------------------- ### Example Request Body for Creating Cluster - Python Source: https://github.com/tencentblueking/blueking-apigateway/blob/master/src/esb/esb/components/bk/apisv2/cc/apidocs/zh_hans/create_set.md This snippet provides an example of the JSON payload required to create a cluster. It includes application credentials, developer account, business ID, and detailed cluster data such as parent ID, set name, description, capacity, and an optional set template ID. ```python { "bk_app_code": "esb_test", "bk_app_secret": "xxx", "bk_token": "xxx", "bk_supplier_account": "123456789", "bk_biz_id": 1, "data": { "bk_parent_id": 1, "bk_set_name": "test-set", "bk_set_desc": "test-set", "bk_capacity": 1000, "description": "description", "set_template_id": 1 } } ``` -------------------------------- ### Example Return Result for Creating a Set - JSON Source: https://github.com/tencentblueking/blueking-apigateway/blob/master/src/esb/esb/components/bk/apisv2/cc/apidocs/en/create_set.md This snippet shows an example of the JSON response received after successfully creating a set. It indicates the operation's success with 'result: true', a zero error code, an empty message, and the ID of the newly created set within the 'data' field. ```JSON { "result": true, "code": 0, "message": "", "data": { "bk_set_id": 1 } } ``` -------------------------------- ### Example Return Result for Component List API - JSON Source: https://github.com/tencentblueking/blueking-apigateway/blob/master/src/esb/esb/components/bk/apisv2/esb/apidocs/en/get_components.md This JSON object demonstrates the expected successful response from the API call. It includes a "result" status, "code", an empty "message" on success, and a "data" array containing details for each component. Each component object provides information such as "name", "label", "version", "method", "path", "type", "system_id", "system_name", and "category". ```JSON { "result": true, "code": 0, "data": [ { "name": "get_all_users", "label": "get all users", "version": "v2", "method": "GET", "path": "/api/c/compapi/v2/bk_login/get_all_users/", "type": 2, "system_id": 1, "system_name": "BK_LOGIN", "category": "component" }, { "name": "get_api_check_component_exist", "label": "check_component_exist", "version": "", "method": "GET", "path": "/api/c/self-service-api/api/check_component_exist/", "type": 2, "system_id": 6, "system_name": "XXXX", "category": "buffet_component" } ], "message": "" } ``` -------------------------------- ### Developing and Testing Core API (Bash) Source: https://github.com/tencentblueking/blueking-apigateway/blob/master/src/core-api/README.md This snippet includes `make` commands for various development and testing tasks such as running tests, generating mock files, formatting code, checking lint, and building a development Docker image. These commands facilitate a robust and efficient development workflow for the core-api project. ```bash # test make test # generate mock files make mock # do format make fmt # check lint make lint # build image make dev-image ``` -------------------------------- ### Example Request Parameters for Batch User Info API (Python) Source: https://github.com/tencentblueking/blueking-apigateway/blob/master/src/esb/esb/components/bk/apisv2/bk_login/apidocs/zh_hans/get_batch_users.md This snippet provides an example of the JSON payload used as request parameters for the batch user information API. It includes authentication details (`bk_app_code`, `bk_app_secret`, `bk_token`) and the required `bk_username_list` array containing usernames to query. ```JSON { "bk_app_code": "esb_test", "bk_app_secret": "xxx", "bk_token": "xxx", "bk_username_list": ["admin", "test"] } ``` -------------------------------- ### Example Return Result for User Role API (Python) Source: https://github.com/tencentblueking/blueking-apigateway/blob/master/src/esb/esb/components/bk/apisv2/bk_login/apidocs/en/get_batch_users_platform_role.md This snippet illustrates the expected JSON response structure from the API call to get user roles. It indicates success/failure, a status code, a message, and a data object containing user-specific role information across different applications. ```Python { "result": true, "code": 0, "message": "OK", "data": { "admin": { "bkdata": [ 1 ], "job": [ 2 ] } } } ``` -------------------------------- ### Generating API Definition and Resources YAML (Go) Source: https://github.com/tencentblueking/blueking-apigateway/blob/master/src/dashboard/apigateway/apigateway/templates/dev_guideline/en/programmable_gateway.md These commands generate `definition.yaml` and `resources.yaml` files locally for testing API definitions and resources in a Go-based project. The `cat` command is used to display the content of the generated files. ```bash go run main.go generate_definition_yaml && cat definition.yaml go run main.go generate_resources_yaml && cat resources.yaml ``` -------------------------------- ### Example Request Parameters for Customize Query Detail - Python Source: https://github.com/tencentblueking/blueking-apigateway/blob/master/src/esb/esb/components/bk/apisv2/cc/apidocs/en/get_custom_query_detail.md This snippet shows an example of the JSON payload used to request customize query details. It includes common authentication parameters (`bk_app_code`, `bk_app_secret`, `bk_token`) along with specific query parameters like `bk_supplier_account`, `bk_biz_id`, and `id`. ```python { "bk_app_code": "esb_test", "bk_app_secret": "xxx", "bk_token": "xxx", "bk_supplier_account": "123456789", "bk_biz_id": 1, "id": "xxx" } ``` -------------------------------- ### Example Request Parameters for Custom Query - Python Source: https://github.com/tencentblueking/blueking-apigateway/blob/master/src/esb/esb/components/bk/apisv2/cc/apidocs/en/get_custom_query_data.md This snippet provides an example of the JSON payload structure required for the custom data query API. It demonstrates how to include authentication details (app code, secret, token) and specific query parameters like business ID, primary key ID, start index, and limit. ```python { "bk_app_code": "esb_test", "bk_app_secret": "xxx", "bk_token": "xxx", "bk_supplier_account": "123456789", "bk_biz_id": 1, "id": "xxx", "start": 0, "limit": 10 } ``` -------------------------------- ### Initializing Development Environment (Shell) Source: https://github.com/tencentblueking/blueking-apigateway/blob/master/src/dashboard/README.md This command initializes the local development environment for the project, setting up necessary configurations and dependencies. ```shell make init ``` -------------------------------- ### Python SDK Example for Syncing Gateway Environment Source: https://github.com/tencentblueking/blueking-apigateway/blob/master/src/dashboard/apigateway/apigateway/data/apidocs/zh/sync_stage.md This Python snippet demonstrates how to use the `bkapi.bk_apigateway` SDK to call the `sync_stage` API. It shows how to obtain a client instance, pass the request body with environment details and proxy configurations, and specify path parameters like `api_name` and request headers. ```python from bkapi.bk_apigateway.shortcuts import get_client_by_request client = get_client_by_request(request) result = client.api.sync_stage( { "name": "prod", "description": "正式环境", "proxy_http": { "timeout": 60, "upstreams": { "loadbalance": "roundrobin", "hosts": [ { "host": "http://api.example.com" } ] } } }, path_params={ "api_name": "demo", }, headers={"Content-Type": "application/json"}, ) ```