This guide covers the API project commands currently implemented under cli/src/cmd/apiproject.
Initializes a new API project in the current working directory.
ap apiproject init --display-name <name> --type <rest> --version <version> --context <context> [--no-interactive]Examples:
ap apiproject init --display-name foo-api --type rest --version 1.0 --context /foo
ap apiproject initBehavior:
- If
--no-interactiveis not used, the command prompts for any missing values. - The project directory is created under the current directory using the
display-namevalue. - The directory name cannot be empty and cannot contain path separators.
- API type validation accepts
restandsoap, but project scaffolding is currently implemented only forrest.
Running ap apiproject init --display-name FooAPI --type rest --version 1.0.0 --context /petstore creates:
FooAPI/
├── .api-platform/
│ └── config.yaml
├── api.yaml
├── gateway.yaml
├── definition.yaml
├── docs/
└── tests/
Created with default project file paths:
version: 1.0.0
filePaths:
deploymentArtifact: ./gateway.yaml
apiMetadata: ./api.yaml
apiDefinition: ./definition.yaml
docs: ./docs
tests: ./tests
governanceRulesets: []
autoSync:
gatewayArtifactFromDefinition: true- Contains API metadata (an
Apimanagement-plane CR) used when publishing to the DevPortal. - The resource name is derived from the display name and version.
spec.referenceIDlinks this metadata to the API deployed on the gateway. After you deploygateway.yaml, setreferenceIDto the gateway's returned API ID (see the end-to-end workflow).
A populated example:
apiVersion: management.api-platform.wso2.com/v1
kind: Api
metadata:
name: "echo-api-v2.0"
spec:
type: REST
displayName: Echo API
version: v2.0
description: Sample HTTP echo/probe API. Requires API key authentication. No subscription plans.
provider: WSO2
referenceID: echo-api-v2.0
tags:
- ping
- api-key
labels:
- default
subscriptionPolicies:
- Gold
- Bronze
visibility: PUBLIC
visibleGroups: []
businessInformation:
businessOwner: Platform Owner
businessOwnerEmail: support@example.com
technicalOwner: API Team
technicalOwnerEmail: architecture@example.com
endpoints:
sandboxUrl: http://localhost:8080/ping
productionUrl: http://localhost:8080/ping- Contains a
RestApigateway deployment artifact (the CR thatap gateway applydeploys). - A starter version is generated with
displayName,version,context, a sample backend URL, and defaultGET,POST,PUT, andDELETEoperations on/*. Edit it to describe your real upstream, policies, and operations. - For more complete, ready-to-use
RestApisamples, seegateway/examples/sample-echo-api.yamlandgateway/examples/petstore-api.yaml.
A populated example:
apiVersion: gateway.api-platform.wso2.com/v1
kind: RestApi
metadata:
name: echo-api-v2.0
annotations:
gateway.api-platform.wso2.com/artifact-id: a1b2c3d4-e000-4000-8000-000000000000
gateway.api-platform.wso2.com/project-id: a1b2c3d4-e000-4000-8000-111111111111
spec:
displayName: Echo API
version: v2.0
context: /postman-echo
upstream:
main:
url: https://postman-echo.com
policies:
- name: api-key-auth
version: v1
params:
key: X-API-Key
in: header
- name: cors
version: v1
params:
allowedOrigins:
- https://localhost:3000
allowedMethods:
- GET
- POST
- OPTIONS
subscriptionPlans:
- Gold
- Bronze
operations:
- method: GET
path: /get
- method: POST
path: /post
- method: GET
path: /status/{code}- Contains a starter OpenAPI 3.0.3 document.
- Includes
GET,POST,PUT,DELETE, andOPTIONSoperations on/*.
- If the target project directory already exists, the command fails.
- Resource names are normalized to a safe lower-case form using the display name and version.
- SOAP project scaffolding is not yet implemented, even though
soapis accepted during initial validation.
An API project is the single source for two destinations: the gateway (where the API is deployed and served, from gateway.yaml) and the DevPortal (where it is published for consumers, from api.yaml + the built artifact). The typical flow ties them together through the gateway-assigned API ID:
ap apiproject init --display-name echo-api --type rest --version v2.0 --context /postman-echo
cd echo-apiThis scaffolds api.yaml, gateway.yaml, definition.yaml, the docs/ and tests/ directories, and .api-platform/config.yaml.
Edit gateway.yaml to point at your real upstream and to declare the policies, operations, and subscription plans the gateway should enforce. Use gateway/examples/sample-echo-api.yaml and gateway/examples/petstore-api.yaml as references.
ap gateway apply -f gateway.yamlThis creates (or updates) the RestApi on the active gateway. The response includes the gateway-assigned API ID — copy it. (You can re-read it any time with ap gateway rest-api get --display-name "Echo API" --version v2.0.) See ap gateway apply for details.
Set spec.referenceID in api.yaml to the gateway API ID from step 3. This links the DevPortal API metadata to the API actually deployed on the gateway:
spec:
referenceID: <gateway-api-id-from-step-3>ap devportal buildThis bundles api.yaml, the API definition, docs, and content into build/devportal.zip (one zip per configured DevPortal). For options and behavior, see ap devportal build.
ap devportal apply -f build/devportal.zipThis uploads the built artifact to the DevPortal; apply reads the kind (RestApi) from the zip's devportal.yaml and routes it accordingly. The target organization is resolved from the DevPortal credentials (no --org flag). See ap devportal apply.
Tip: Before steps 3–6, make sure you have selected the target gateway and DevPortal (
ap gateway use,ap devportal use). The CLI uses the active gateway/DevPortal of the active platform unless you pass--gateway/--display-nameand--platform.
ap gateway apply— deploygateway.yamlto a gateway (see the Gateway CLI reference)ap devportal build— build the DevPortal artifact (see the DevPortal CLI reference)ap devportal apply— apply an artifact (REST API zip) or CR (organization, subscription plans) to a DevPortal organization