feat: Add Official Microsoft & Gemini Skills (845+ Total)
🚀 Impact Significantly expands the capabilities of **Antigravity Awesome Skills** by integrating official skill collections from **Microsoft** and **Google Gemini**. This update increases the total skill count to **845+**, making the library even more comprehensive for AI coding assistants. ✨ Key Changes 1. New Official Skills - **Microsoft Skills**: Added a massive collection of official skills from [microsoft/skills](https://github.com/microsoft/skills). - Includes Azure, .NET, Python, TypeScript, and Semantic Kernel skills. - Preserves the original directory structure under `skills/official/microsoft/`. - Includes plugin skills from the `.github/plugins` directory. - **Gemini Skills**: Added official Gemini API development skills under `skills/gemini-api-dev/`. 2. New Scripts & Tooling - **`scripts/sync_microsoft_skills.py`**: A robust synchronization script that: - Clones the official Microsoft repository. - Preserves the original directory heirarchy. - Handles symlinks and plugin locations. - Generates attribution metadata. - **`scripts/tests/inspect_microsoft_repo.py`**: Debug tool to inspect the remote repository structure. - **`scripts/tests/test_comprehensive_coverage.py`**: Verification script to ensure 100% of skills are captured during sync. 3. Core Improvements - **`scripts/generate_index.py`**: Enhanced frontmatter parsing to safely handle unquoted values containing `@` symbols and commas (fixing issues with some Microsoft skill descriptions). - **`package.json`**: Added `sync:microsoft` and `sync:all-official` scripts for easy maintenance. 4. Documentation - Updated `README.md` to reflect the new skill counts (845+) and added Microsoft/Gemini to the provider list. - Updated `CATALOG.md` and `skills_index.json` with the new skills. 🧪 Verification - Ran `scripts/tests/test_comprehensive_coverage.py` to verify all Microsoft skills are detected. - Validated `generate_index.py` fixes by successfully indexing the new skills.
This commit is contained in:
411
skills/official/microsoft/dotnet/integration/apicenter/SKILL.md
Normal file
411
skills/official/microsoft/dotnet/integration/apicenter/SKILL.md
Normal file
@@ -0,0 +1,411 @@
|
||||
---
|
||||
name: azure-mgmt-apicenter-dotnet
|
||||
description: |
|
||||
Azure API Center SDK for .NET. Centralized API inventory management with governance, versioning, and discovery. Use for creating API services, workspaces, APIs, versions, definitions, environments, deployments, and metadata schemas. Triggers: "API Center", "ApiCenterService", "ApiCenterWorkspace", "ApiCenterApi", "API inventory", "API governance", "API versioning", "API catalog", "API discovery".
|
||||
package: Azure.ResourceManager.ApiCenter
|
||||
---
|
||||
|
||||
# Azure.ResourceManager.ApiCenter (.NET)
|
||||
|
||||
Centralized API inventory and governance SDK for managing APIs across your organization.
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
dotnet add package Azure.ResourceManager.ApiCenter
|
||||
dotnet add package Azure.Identity
|
||||
```
|
||||
|
||||
**Current Version**: v1.0.0 (GA)
|
||||
**API Version**: 2024-03-01
|
||||
|
||||
## Environment Variables
|
||||
|
||||
```bash
|
||||
AZURE_SUBSCRIPTION_ID=<your-subscription-id>
|
||||
AZURE_RESOURCE_GROUP=<your-resource-group>
|
||||
AZURE_APICENTER_SERVICE_NAME=<your-apicenter-service>
|
||||
```
|
||||
|
||||
## Authentication
|
||||
|
||||
```csharp
|
||||
using Azure.Identity;
|
||||
using Azure.ResourceManager;
|
||||
using Azure.ResourceManager.ApiCenter;
|
||||
|
||||
ArmClient client = new ArmClient(new DefaultAzureCredential());
|
||||
```
|
||||
|
||||
## Resource Hierarchy
|
||||
|
||||
```
|
||||
Subscription
|
||||
└── ResourceGroup
|
||||
└── ApiCenterService # API inventory service
|
||||
├── Workspace # Logical grouping of APIs
|
||||
│ ├── Api # API definition
|
||||
│ │ └── ApiVersion # Version of the API
|
||||
│ │ └── ApiDefinition # OpenAPI/GraphQL/etc specification
|
||||
│ ├── Environment # Deployment target (dev/staging/prod)
|
||||
│ └── Deployment # API deployed to environment
|
||||
└── MetadataSchema # Custom metadata definitions
|
||||
```
|
||||
|
||||
## Core Workflows
|
||||
|
||||
### 1. Create API Center Service
|
||||
|
||||
```csharp
|
||||
using Azure.ResourceManager.ApiCenter;
|
||||
using Azure.ResourceManager.ApiCenter.Models;
|
||||
|
||||
ResourceGroupResource resourceGroup = await client
|
||||
.GetDefaultSubscriptionAsync()
|
||||
.Result
|
||||
.GetResourceGroupAsync("my-resource-group");
|
||||
|
||||
ApiCenterServiceCollection services = resourceGroup.GetApiCenterServices();
|
||||
|
||||
ApiCenterServiceData data = new ApiCenterServiceData(AzureLocation.EastUS)
|
||||
{
|
||||
Identity = new ManagedServiceIdentity(ManagedServiceIdentityType.SystemAssigned)
|
||||
};
|
||||
|
||||
ArmOperation<ApiCenterServiceResource> operation = await services
|
||||
.CreateOrUpdateAsync(WaitUntil.Completed, "my-api-center", data);
|
||||
|
||||
ApiCenterServiceResource service = operation.Value;
|
||||
```
|
||||
|
||||
### 2. Create Workspace
|
||||
|
||||
```csharp
|
||||
ApiCenterWorkspaceCollection workspaces = service.GetApiCenterWorkspaces();
|
||||
|
||||
ApiCenterWorkspaceData workspaceData = new ApiCenterWorkspaceData
|
||||
{
|
||||
Title = "Engineering APIs",
|
||||
Description = "APIs owned by the engineering team"
|
||||
};
|
||||
|
||||
ArmOperation<ApiCenterWorkspaceResource> operation = await workspaces
|
||||
.CreateOrUpdateAsync(WaitUntil.Completed, "engineering", workspaceData);
|
||||
|
||||
ApiCenterWorkspaceResource workspace = operation.Value;
|
||||
```
|
||||
|
||||
### 3. Create API
|
||||
|
||||
```csharp
|
||||
ApiCenterApiCollection apis = workspace.GetApiCenterApis();
|
||||
|
||||
ApiCenterApiData apiData = new ApiCenterApiData
|
||||
{
|
||||
Title = "Orders API",
|
||||
Description = "API for managing customer orders",
|
||||
Kind = ApiKind.Rest,
|
||||
LifecycleStage = ApiLifecycleStage.Production,
|
||||
TermsOfService = new ApiTermsOfService
|
||||
{
|
||||
Uri = new Uri("https://example.com/terms")
|
||||
},
|
||||
ExternalDocumentation =
|
||||
{
|
||||
new ApiExternalDocumentation
|
||||
{
|
||||
Title = "Documentation",
|
||||
Uri = new Uri("https://docs.example.com/orders")
|
||||
}
|
||||
},
|
||||
Contacts =
|
||||
{
|
||||
new ApiContact
|
||||
{
|
||||
Name = "API Support",
|
||||
Email = "api-support@example.com"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Add custom metadata
|
||||
apiData.CustomProperties = BinaryData.FromObjectAsJson(new
|
||||
{
|
||||
team = "orders-team",
|
||||
costCenter = "CC-1234"
|
||||
});
|
||||
|
||||
ArmOperation<ApiCenterApiResource> operation = await apis
|
||||
.CreateOrUpdateAsync(WaitUntil.Completed, "orders-api", apiData);
|
||||
|
||||
ApiCenterApiResource api = operation.Value;
|
||||
```
|
||||
|
||||
### 4. Create API Version
|
||||
|
||||
```csharp
|
||||
ApiCenterApiVersionCollection versions = api.GetApiCenterApiVersions();
|
||||
|
||||
ApiCenterApiVersionData versionData = new ApiCenterApiVersionData
|
||||
{
|
||||
Title = "v1.0.0",
|
||||
LifecycleStage = ApiLifecycleStage.Production
|
||||
};
|
||||
|
||||
ArmOperation<ApiCenterApiVersionResource> operation = await versions
|
||||
.CreateOrUpdateAsync(WaitUntil.Completed, "v1-0-0", versionData);
|
||||
|
||||
ApiCenterApiVersionResource version = operation.Value;
|
||||
```
|
||||
|
||||
### 5. Create API Definition (Upload OpenAPI Spec)
|
||||
|
||||
```csharp
|
||||
ApiCenterApiDefinitionCollection definitions = version.GetApiCenterApiDefinitions();
|
||||
|
||||
ApiCenterApiDefinitionData definitionData = new ApiCenterApiDefinitionData
|
||||
{
|
||||
Title = "OpenAPI Specification",
|
||||
Description = "Orders API OpenAPI 3.0 definition"
|
||||
};
|
||||
|
||||
ArmOperation<ApiCenterApiDefinitionResource> operation = await definitions
|
||||
.CreateOrUpdateAsync(WaitUntil.Completed, "openapi", definitionData);
|
||||
|
||||
ApiCenterApiDefinitionResource definition = operation.Value;
|
||||
|
||||
// Import specification
|
||||
string openApiSpec = await File.ReadAllTextAsync("orders-api.yaml");
|
||||
|
||||
ApiSpecImportContent importContent = new ApiSpecImportContent
|
||||
{
|
||||
Format = ApiSpecImportSourceFormat.Inline,
|
||||
Value = openApiSpec,
|
||||
Specification = new ApiSpecImportSpecification
|
||||
{
|
||||
Name = "openapi",
|
||||
Version = "3.0.1"
|
||||
}
|
||||
};
|
||||
|
||||
await definition.ImportSpecificationAsync(WaitUntil.Completed, importContent);
|
||||
```
|
||||
|
||||
### 6. Export API Specification
|
||||
|
||||
```csharp
|
||||
ApiCenterApiDefinitionResource definition = await client
|
||||
.GetApiCenterApiDefinitionResource(definitionResourceId)
|
||||
.GetAsync();
|
||||
|
||||
ArmOperation<ApiSpecExportResult> operation = await definition
|
||||
.ExportSpecificationAsync(WaitUntil.Completed);
|
||||
|
||||
ApiSpecExportResult result = operation.Value;
|
||||
|
||||
// result.Format - e.g., "inline"
|
||||
// result.Value - the specification content
|
||||
```
|
||||
|
||||
### 7. Create Environment
|
||||
|
||||
```csharp
|
||||
ApiCenterEnvironmentCollection environments = workspace.GetApiCenterEnvironments();
|
||||
|
||||
ApiCenterEnvironmentData envData = new ApiCenterEnvironmentData
|
||||
{
|
||||
Title = "Production",
|
||||
Description = "Production environment",
|
||||
Kind = ApiCenterEnvironmentKind.Production,
|
||||
Server = new ApiCenterEnvironmentServer
|
||||
{
|
||||
ManagementPortalUris = { new Uri("https://portal.azure.com") }
|
||||
},
|
||||
Onboarding = new EnvironmentOnboardingModel
|
||||
{
|
||||
Instructions = "Contact platform team for access",
|
||||
DeveloperPortalUris = { new Uri("https://developer.example.com") }
|
||||
}
|
||||
};
|
||||
|
||||
ArmOperation<ApiCenterEnvironmentResource> operation = await environments
|
||||
.CreateOrUpdateAsync(WaitUntil.Completed, "production", envData);
|
||||
```
|
||||
|
||||
### 8. Create Deployment
|
||||
|
||||
```csharp
|
||||
ApiCenterDeploymentCollection deployments = workspace.GetApiCenterDeployments();
|
||||
|
||||
// Get environment resource ID
|
||||
ResourceIdentifier envResourceId = ApiCenterEnvironmentResource.CreateResourceIdentifier(
|
||||
subscriptionId, resourceGroupName, serviceName, workspaceName, "production");
|
||||
|
||||
// Get API definition resource ID
|
||||
ResourceIdentifier definitionResourceId = ApiCenterApiDefinitionResource.CreateResourceIdentifier(
|
||||
subscriptionId, resourceGroupName, serviceName, workspaceName,
|
||||
"orders-api", "v1-0-0", "openapi");
|
||||
|
||||
ApiCenterDeploymentData deploymentData = new ApiCenterDeploymentData
|
||||
{
|
||||
Title = "Orders API - Production",
|
||||
Description = "Production deployment of Orders API v1.0.0",
|
||||
EnvironmentId = envResourceId,
|
||||
DefinitionId = definitionResourceId,
|
||||
State = ApiCenterDeploymentState.Active,
|
||||
Server = new ApiCenterDeploymentServer
|
||||
{
|
||||
RuntimeUris = { new Uri("https://api.example.com/orders") }
|
||||
}
|
||||
};
|
||||
|
||||
ArmOperation<ApiCenterDeploymentResource> operation = await deployments
|
||||
.CreateOrUpdateAsync(WaitUntil.Completed, "orders-api-prod", deploymentData);
|
||||
```
|
||||
|
||||
### 9. Create Metadata Schema
|
||||
|
||||
```csharp
|
||||
ApiCenterMetadataSchemaCollection schemas = service.GetApiCenterMetadataSchemas();
|
||||
|
||||
string jsonSchema = """
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"team": {
|
||||
"type": "string",
|
||||
"title": "Owning Team"
|
||||
},
|
||||
"costCenter": {
|
||||
"type": "string",
|
||||
"title": "Cost Center"
|
||||
},
|
||||
"dataClassification": {
|
||||
"type": "string",
|
||||
"enum": ["public", "internal", "confidential"],
|
||||
"title": "Data Classification"
|
||||
}
|
||||
},
|
||||
"required": ["team"]
|
||||
}
|
||||
""";
|
||||
|
||||
ApiCenterMetadataSchemaData schemaData = new ApiCenterMetadataSchemaData
|
||||
{
|
||||
Schema = jsonSchema,
|
||||
AssignedTo =
|
||||
{
|
||||
new MetadataAssignment
|
||||
{
|
||||
Entity = MetadataAssignmentEntity.Api,
|
||||
Required = true
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
ArmOperation<ApiCenterMetadataSchemaResource> operation = await schemas
|
||||
.CreateOrUpdateAsync(WaitUntil.Completed, "api-metadata", schemaData);
|
||||
```
|
||||
|
||||
### 10. List and Search APIs
|
||||
|
||||
```csharp
|
||||
// List all APIs in a workspace
|
||||
ApiCenterWorkspaceResource workspace = await client
|
||||
.GetApiCenterWorkspaceResource(workspaceResourceId)
|
||||
.GetAsync();
|
||||
|
||||
await foreach (ApiCenterApiResource api in workspace.GetApiCenterApis())
|
||||
{
|
||||
Console.WriteLine($"API: {api.Data.Title}");
|
||||
Console.WriteLine($" Kind: {api.Data.Kind}");
|
||||
Console.WriteLine($" Stage: {api.Data.LifecycleStage}");
|
||||
|
||||
// List versions
|
||||
await foreach (ApiCenterApiVersionResource version in api.GetApiCenterApiVersions())
|
||||
{
|
||||
Console.WriteLine($" Version: {version.Data.Title}");
|
||||
}
|
||||
}
|
||||
|
||||
// List environments
|
||||
await foreach (ApiCenterEnvironmentResource env in workspace.GetApiCenterEnvironments())
|
||||
{
|
||||
Console.WriteLine($"Environment: {env.Data.Title} ({env.Data.Kind})");
|
||||
}
|
||||
|
||||
// List deployments
|
||||
await foreach (ApiCenterDeploymentResource deployment in workspace.GetApiCenterDeployments())
|
||||
{
|
||||
Console.WriteLine($"Deployment: {deployment.Data.Title}");
|
||||
Console.WriteLine($" State: {deployment.Data.State}");
|
||||
}
|
||||
```
|
||||
|
||||
## Key Types Reference
|
||||
|
||||
| Type | Purpose |
|
||||
|------|---------|
|
||||
| `ApiCenterServiceResource` | API Center service instance |
|
||||
| `ApiCenterWorkspaceResource` | Logical grouping of APIs |
|
||||
| `ApiCenterApiResource` | Individual API |
|
||||
| `ApiCenterApiVersionResource` | Version of an API |
|
||||
| `ApiCenterApiDefinitionResource` | API specification (OpenAPI, etc.) |
|
||||
| `ApiCenterEnvironmentResource` | Deployment environment |
|
||||
| `ApiCenterDeploymentResource` | API deployment to environment |
|
||||
| `ApiCenterMetadataSchemaResource` | Custom metadata schema |
|
||||
| `ApiKind` | rest, graphql, grpc, soap, webhook, websocket, mcp |
|
||||
| `ApiLifecycleStage` | design, development, testing, preview, production, deprecated, retired |
|
||||
| `ApiCenterEnvironmentKind` | development, testing, staging, production |
|
||||
| `ApiCenterDeploymentState` | active, inactive |
|
||||
|
||||
## Best Practices
|
||||
|
||||
1. **Organize with workspaces** — Group APIs by team, domain, or product
|
||||
2. **Use metadata schemas** — Define custom properties for governance
|
||||
3. **Track lifecycle stages** — Keep API status current (design → production → deprecated)
|
||||
4. **Document environments** — Include onboarding instructions and portal URIs
|
||||
5. **Version consistently** — Use semantic versioning for API versions
|
||||
6. **Import specifications** — Upload OpenAPI/GraphQL specs for discovery
|
||||
7. **Link deployments** — Connect APIs to their runtime environments
|
||||
8. **Use managed identity** — Enable SystemAssigned identity for secure integrations
|
||||
|
||||
## Error Handling
|
||||
|
||||
```csharp
|
||||
using Azure;
|
||||
|
||||
try
|
||||
{
|
||||
ArmOperation<ApiCenterApiResource> operation = await apis
|
||||
.CreateOrUpdateAsync(WaitUntil.Completed, "my-api", apiData);
|
||||
}
|
||||
catch (RequestFailedException ex) when (ex.Status == 409)
|
||||
{
|
||||
Console.WriteLine("API already exists with conflicting configuration");
|
||||
}
|
||||
catch (RequestFailedException ex) when (ex.Status == 400)
|
||||
{
|
||||
Console.WriteLine($"Invalid request: {ex.Message}");
|
||||
}
|
||||
catch (RequestFailedException ex)
|
||||
{
|
||||
Console.WriteLine($"Azure error: {ex.Status} - {ex.Message}");
|
||||
}
|
||||
```
|
||||
|
||||
## Related SDKs
|
||||
|
||||
| SDK | Purpose | Install |
|
||||
|-----|---------|---------|
|
||||
| `Azure.ResourceManager.ApiCenter` | API Center management (this SDK) | `dotnet add package Azure.ResourceManager.ApiCenter` |
|
||||
| `Azure.ResourceManager.ApiManagement` | API gateway and policies | `dotnet add package Azure.ResourceManager.ApiManagement` |
|
||||
|
||||
## Reference Links
|
||||
|
||||
| Resource | URL |
|
||||
|----------|-----|
|
||||
| NuGet Package | https://www.nuget.org/packages/Azure.ResourceManager.ApiCenter |
|
||||
| API Reference | https://learn.microsoft.com/dotnet/api/azure.resourcemanager.apicenter |
|
||||
| Product Documentation | https://learn.microsoft.com/azure/api-center/ |
|
||||
| GitHub Source | https://github.com/Azure/azure-sdk-for-net/tree/main/sdk/apicenter/Azure.ResourceManager.ApiCenter |
|
||||
@@ -0,0 +1,310 @@
|
||||
---
|
||||
name: azure-mgmt-apimanagement-dotnet
|
||||
description: |
|
||||
Azure Resource Manager SDK for API Management in .NET. Use for MANAGEMENT PLANE operations: creating/managing APIM services, APIs, products, subscriptions, policies, users, groups, gateways, and backends via Azure Resource Manager. Triggers: "API Management", "APIM service", "create APIM", "manage APIs", "ApiManagementServiceResource", "API policies", "APIM products", "APIM subscriptions".
|
||||
package: Azure.ResourceManager.ApiManagement
|
||||
---
|
||||
|
||||
# Azure.ResourceManager.ApiManagement (.NET)
|
||||
|
||||
Management plane SDK for provisioning and managing Azure API Management resources via Azure Resource Manager.
|
||||
|
||||
> **⚠️ Management vs Data Plane**
|
||||
> - **This SDK (Azure.ResourceManager.ApiManagement)**: Create services, APIs, products, subscriptions, policies, users, groups
|
||||
> - **Data Plane**: Direct API calls to your APIM gateway endpoints
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
dotnet add package Azure.ResourceManager.ApiManagement
|
||||
dotnet add package Azure.Identity
|
||||
```
|
||||
|
||||
**Current Version**: v1.3.0
|
||||
|
||||
## Environment Variables
|
||||
|
||||
```bash
|
||||
AZURE_SUBSCRIPTION_ID=<your-subscription-id>
|
||||
# For service principal auth (optional)
|
||||
AZURE_TENANT_ID=<tenant-id>
|
||||
AZURE_CLIENT_ID=<client-id>
|
||||
AZURE_CLIENT_SECRET=<client-secret>
|
||||
```
|
||||
|
||||
## Authentication
|
||||
|
||||
```csharp
|
||||
using Azure.Identity;
|
||||
using Azure.ResourceManager;
|
||||
using Azure.ResourceManager.ApiManagement;
|
||||
|
||||
// Always use DefaultAzureCredential
|
||||
var credential = new DefaultAzureCredential();
|
||||
var armClient = new ArmClient(credential);
|
||||
|
||||
// Get subscription
|
||||
var subscriptionId = Environment.GetEnvironmentVariable("AZURE_SUBSCRIPTION_ID");
|
||||
var subscription = armClient.GetSubscriptionResource(
|
||||
new ResourceIdentifier($"/subscriptions/{subscriptionId}"));
|
||||
```
|
||||
|
||||
## Resource Hierarchy
|
||||
|
||||
```
|
||||
ArmClient
|
||||
└── SubscriptionResource
|
||||
└── ResourceGroupResource
|
||||
└── ApiManagementServiceResource
|
||||
├── ApiResource
|
||||
│ ├── ApiOperationResource
|
||||
│ │ └── ApiOperationPolicyResource
|
||||
│ ├── ApiPolicyResource
|
||||
│ ├── ApiSchemaResource
|
||||
│ └── ApiDiagnosticResource
|
||||
├── ApiManagementProductResource
|
||||
│ ├── ProductApiResource
|
||||
│ ├── ProductGroupResource
|
||||
│ └── ProductPolicyResource
|
||||
├── ApiManagementSubscriptionResource
|
||||
├── ApiManagementPolicyResource
|
||||
├── ApiManagementUserResource
|
||||
├── ApiManagementGroupResource
|
||||
├── ApiManagementBackendResource
|
||||
├── ApiManagementGatewayResource
|
||||
├── ApiManagementCertificateResource
|
||||
├── ApiManagementNamedValueResource
|
||||
└── ApiManagementLoggerResource
|
||||
```
|
||||
|
||||
## Core Workflow
|
||||
|
||||
### 1. Create API Management Service
|
||||
|
||||
```csharp
|
||||
using Azure.ResourceManager.ApiManagement;
|
||||
using Azure.ResourceManager.ApiManagement.Models;
|
||||
|
||||
// Get resource group
|
||||
var resourceGroup = await subscription
|
||||
.GetResourceGroupAsync("my-resource-group");
|
||||
|
||||
// Define service
|
||||
var serviceData = new ApiManagementServiceData(
|
||||
location: AzureLocation.EastUS,
|
||||
sku: new ApiManagementServiceSkuProperties(
|
||||
ApiManagementServiceSkuType.Developer,
|
||||
capacity: 1),
|
||||
publisherEmail: "admin@contoso.com",
|
||||
publisherName: "Contoso");
|
||||
|
||||
// Create service (long-running operation - can take 30+ minutes)
|
||||
var serviceCollection = resourceGroup.Value.GetApiManagementServices();
|
||||
var operation = await serviceCollection.CreateOrUpdateAsync(
|
||||
WaitUntil.Completed,
|
||||
"my-apim-service",
|
||||
serviceData);
|
||||
|
||||
ApiManagementServiceResource service = operation.Value;
|
||||
```
|
||||
|
||||
### 2. Create an API
|
||||
|
||||
```csharp
|
||||
var apiData = new ApiCreateOrUpdateContent
|
||||
{
|
||||
DisplayName = "My API",
|
||||
Path = "myapi",
|
||||
Protocols = { ApiOperationInvokableProtocol.Https },
|
||||
ServiceUri = new Uri("https://backend.contoso.com/api")
|
||||
};
|
||||
|
||||
var apiCollection = service.GetApis();
|
||||
var apiOperation = await apiCollection.CreateOrUpdateAsync(
|
||||
WaitUntil.Completed,
|
||||
"my-api",
|
||||
apiData);
|
||||
|
||||
ApiResource api = apiOperation.Value;
|
||||
```
|
||||
|
||||
### 3. Create a Product
|
||||
|
||||
```csharp
|
||||
var productData = new ApiManagementProductData
|
||||
{
|
||||
DisplayName = "Starter",
|
||||
Description = "Starter tier with limited access",
|
||||
IsSubscriptionRequired = true,
|
||||
IsApprovalRequired = false,
|
||||
SubscriptionsLimit = 1,
|
||||
State = ApiManagementProductState.Published
|
||||
};
|
||||
|
||||
var productCollection = service.GetApiManagementProducts();
|
||||
var productOperation = await productCollection.CreateOrUpdateAsync(
|
||||
WaitUntil.Completed,
|
||||
"starter",
|
||||
productData);
|
||||
|
||||
ApiManagementProductResource product = productOperation.Value;
|
||||
|
||||
// Add API to product
|
||||
await product.GetProductApis().CreateOrUpdateAsync(
|
||||
WaitUntil.Completed,
|
||||
"my-api");
|
||||
```
|
||||
|
||||
### 4. Create a Subscription
|
||||
|
||||
```csharp
|
||||
var subscriptionData = new ApiManagementSubscriptionCreateOrUpdateContent
|
||||
{
|
||||
DisplayName = "My Subscription",
|
||||
Scope = $"/products/{product.Data.Name}",
|
||||
State = ApiManagementSubscriptionState.Active
|
||||
};
|
||||
|
||||
var subscriptionCollection = service.GetApiManagementSubscriptions();
|
||||
var subOperation = await subscriptionCollection.CreateOrUpdateAsync(
|
||||
WaitUntil.Completed,
|
||||
"my-subscription",
|
||||
subscriptionData);
|
||||
|
||||
ApiManagementSubscriptionResource subscription = subOperation.Value;
|
||||
|
||||
// Get subscription keys
|
||||
var keys = await subscription.GetSecretsAsync();
|
||||
Console.WriteLine($"Primary Key: {keys.Value.PrimaryKey}");
|
||||
```
|
||||
|
||||
### 5. Set API Policy
|
||||
|
||||
```csharp
|
||||
var policyXml = @"
|
||||
<policies>
|
||||
<inbound>
|
||||
<rate-limit calls=""100"" renewal-period=""60"" />
|
||||
<set-header name=""X-Custom-Header"" exists-action=""override"">
|
||||
<value>CustomValue</value>
|
||||
</set-header>
|
||||
<base />
|
||||
</inbound>
|
||||
<backend>
|
||||
<base />
|
||||
</backend>
|
||||
<outbound>
|
||||
<base />
|
||||
</outbound>
|
||||
<on-error>
|
||||
<base />
|
||||
</on-error>
|
||||
</policies>";
|
||||
|
||||
var policyData = new PolicyContractData
|
||||
{
|
||||
Value = policyXml,
|
||||
Format = PolicyContentFormat.Xml
|
||||
};
|
||||
|
||||
await api.GetApiPolicy().CreateOrUpdateAsync(
|
||||
WaitUntil.Completed,
|
||||
policyData);
|
||||
```
|
||||
|
||||
### 6. Backup and Restore
|
||||
|
||||
```csharp
|
||||
// Backup
|
||||
var backupParams = new ApiManagementServiceBackupRestoreContent(
|
||||
storageAccount: "mystorageaccount",
|
||||
containerName: "apim-backups",
|
||||
backupName: "backup-2024-01-15")
|
||||
{
|
||||
AccessType = StorageAccountAccessType.SystemAssignedManagedIdentity
|
||||
};
|
||||
|
||||
await service.BackupAsync(WaitUntil.Completed, backupParams);
|
||||
|
||||
// Restore
|
||||
await service.RestoreAsync(WaitUntil.Completed, backupParams);
|
||||
```
|
||||
|
||||
## Key Types Reference
|
||||
|
||||
| Type | Purpose |
|
||||
|------|---------|
|
||||
| `ArmClient` | Entry point for all ARM operations |
|
||||
| `ApiManagementServiceResource` | Represents an APIM service instance |
|
||||
| `ApiManagementServiceCollection` | Collection for service CRUD |
|
||||
| `ApiResource` | Represents an API |
|
||||
| `ApiManagementProductResource` | Represents a product |
|
||||
| `ApiManagementSubscriptionResource` | Represents a subscription |
|
||||
| `ApiManagementPolicyResource` | Service-level policy |
|
||||
| `ApiPolicyResource` | API-level policy |
|
||||
| `ApiManagementUserResource` | Represents a user |
|
||||
| `ApiManagementGroupResource` | Represents a group |
|
||||
| `ApiManagementBackendResource` | Represents a backend service |
|
||||
| `ApiManagementGatewayResource` | Represents a self-hosted gateway |
|
||||
|
||||
## SKU Types
|
||||
|
||||
| SKU | Purpose | Capacity |
|
||||
|-----|---------|----------|
|
||||
| `Developer` | Development/testing (no SLA) | 1 |
|
||||
| `Basic` | Entry-level production | 1-2 |
|
||||
| `Standard` | Medium workloads | 1-4 |
|
||||
| `Premium` | High availability, multi-region | 1-12 per region |
|
||||
| `Consumption` | Serverless, pay-per-call | N/A |
|
||||
|
||||
## Best Practices
|
||||
|
||||
1. **Use `WaitUntil.Completed`** for operations that must finish before proceeding
|
||||
2. **Use `WaitUntil.Started`** for long operations like service creation (30+ min)
|
||||
3. **Always use `DefaultAzureCredential`** — never hardcode keys
|
||||
4. **Handle `RequestFailedException`** for ARM API errors
|
||||
5. **Use `CreateOrUpdateAsync`** for idempotent operations
|
||||
6. **Navigate hierarchy** via `Get*` methods (e.g., `service.GetApis()`)
|
||||
7. **Policy format** — Use XML format for policies; JSON is also supported
|
||||
8. **Service creation** — Developer SKU is fastest for testing (~15-30 min)
|
||||
|
||||
## Error Handling
|
||||
|
||||
```csharp
|
||||
using Azure;
|
||||
|
||||
try
|
||||
{
|
||||
var operation = await serviceCollection.CreateOrUpdateAsync(
|
||||
WaitUntil.Completed, serviceName, serviceData);
|
||||
}
|
||||
catch (RequestFailedException ex) when (ex.Status == 409)
|
||||
{
|
||||
Console.WriteLine("Service already exists");
|
||||
}
|
||||
catch (RequestFailedException ex) when (ex.Status == 400)
|
||||
{
|
||||
Console.WriteLine($"Bad request: {ex.Message}");
|
||||
}
|
||||
catch (RequestFailedException ex)
|
||||
{
|
||||
Console.WriteLine($"ARM Error: {ex.Status} - {ex.ErrorCode}: {ex.Message}");
|
||||
}
|
||||
```
|
||||
|
||||
## Reference Files
|
||||
|
||||
| File | When to Read |
|
||||
|------|--------------|
|
||||
| [references/service-management.md](references/service-management.md) | Service CRUD, SKUs, networking, backup/restore |
|
||||
| [references/apis-operations.md](references/apis-operations.md) | APIs, operations, schemas, versioning |
|
||||
| [references/products-subscriptions.md](references/products-subscriptions.md) | Products, subscriptions, access control |
|
||||
| [references/policies.md](references/policies.md) | Policy XML patterns, scopes, common policies |
|
||||
|
||||
## Related Resources
|
||||
|
||||
| Resource | Purpose |
|
||||
|----------|---------|
|
||||
| [API Management Documentation](https://learn.microsoft.com/en-us/azure/api-management/) | Official Azure docs |
|
||||
| [Policy Reference](https://learn.microsoft.com/en-us/azure/api-management/api-management-policies) | Complete policy reference |
|
||||
| [SDK Reference](https://learn.microsoft.com/en-us/dotnet/api/azure.resourcemanager.apimanagement) | .NET API reference |
|
||||
Reference in New Issue
Block a user