Skip to content

Your first API, step by step

TutorialLearn by doing, one step after another.

The quick start used the wizard. This page does the same by hand, which is how you work from the second API on, and shows the equivalent YAML and terminal commands.

The video does these steps on Apinx Cloud: an upstream, an API with two operations of its own (read and delete a product), an API key, a rate limit, a transformation on one operation, an application with its key, and the same API edited as YAML.

Your first API on Apinx Cloud. 9 minutes, narrated, with subtitles. Also on apinx.io.

Create the API

  1. Develop → Upstreams → New upstream: name orders-backend, target http://localhost:3000 (or keep the demo backend).
  2. Develop → APIs → New API: name orders, backend orders-backend, base path /orders. Leave "Add a catch-all operation" ticked: it forwards every path under /orders to the backend. The box needs a backend; an API created without one gets no operation, and you add operations afterwards, each naming its own backend.
  3. The banner shows undeployed changes. Review and deploy shows exactly what goes live; enter a message and Deploy all changes.
curl -i localhost:8080/orders/echo     # 200 from the backend, /orders stripped

The same as a file, imported with apinxctl import and deployed with apinxctl publish:

apiVersion: apinx/v1
kind: API
name: orders
base_path: /orders
upstream: orders-backend
strip_prefix: true
operations:
  - name: all
    path: /{rest...}

Protect it

  1. Publish → Consumers → New application: mobile. Issue key; copy it, it is shown once.
  2. Develop → APIs → orders → Develop tab → Add policy: api-key (defaults are fine), then rate-limit with limit 100 and window 1m. Each change is saved to the draft.
  3. Review and deploy.

The Develop tab now draws both policies in the flow:

The Develop tab of the orders API, with its request flow and response flow The Develop tab of the orders API, with its request flow and response flow 1 2 3 4 5 6

  1. The tabs of one API. Develop is where its policies are; Code shows the same thing as YAML.
  2. API flow holds what runs for every operation. Select an operation below it to see or change that operation only.
  3. The request flow, drawn in the order the gateway runs it, from the client to the backend.
  4. Add a policy opens the catalogue. The new step goes to its own stage, whatever position you add it in.
  5. The tag says where a step comes from: set here, inherited, or enforced by a flow hook.
  6. The response flow, from the backend back to the client.
curl -i localhost:8080/orders/echo                      # 401 APX-PL-0001
curl -i -H "X-API-Key: apk_…" localhost:8080/orders/echo  # 200, RateLimit-Remaining: 99

The backend receives X-Apinx-Application: mobile; the key itself is stripped.

policies:
  - type: api-key
  - type: rate-limit
    config:
      limit: 100
      window: 1m

Make one operation public

Open the operation, add api-key as switch off. The effective policies view shows the resulting chain and where each entry came from.

operations:
  - name: health
    path: /health
    policies:
      - type: api-key
        enabled: false

From the catch-all to operations of their own

The catch-all forwards everything, so the gateway learns which endpoints callers really use. Operations → Paths through the catch-all lists them for the last 30 days, most called first: method, path, calls, errors, last status and when each was last seen. Numbers and IDs in a path show as {id}, so /orders/7 and /orders/8 are one row (/orders/{id}).

  1. Add operation on a row opens the operation editor with its name, path and method filled in. Give it its own policies if it needs them, and save.
  2. The row now says Operation get-orders: once deployed, that operation takes the path.
  3. After deploying, Clear list and wait: anything that still arrives is a path without an operation of its own.
  4. When nothing new arrives, switch the catch-all off (the switch at the start of its row on the Operations tab) and deploy. Calls to paths without an operation now get 404.

An operation that is off stays in the API with all its settings, but the gateway acts as if it did not exist: its requests go to the next operation that matches, such as the catch-all, or get 404. Switch it on again and deploy to serve it. In YAML:

operations:
  - name: all
    path: /{rest...}
    enabled: false

Up to 500 paths are kept per catch-all operation; beyond that, calls count under Other paths. A path not seen for 30 days is dropped. The list needs analytics (on by default).

Your first SOAP API

The demo backend also serves a small SOAP service, OrderService, at /soap/orders on port 9100, with its WSDL at ?wsdl. Publishing it as JSON takes an import and a deploy.

  1. Save the WSDL: curl -s localhost:9100/soap/orders?wsdl -o orders.wsdl (or open the address in a browser and copy the text).
  2. Admin → Import & export → Import an API → WSDL: choose the file or paste it. The preview proposes the API order-service, a backend order-service-soap at the demo's address, and four operations, POST /get-order, /list-orders, /create-order and /cancel-order, each with its envelope template and a JSON example. Set the base path to /orders and Create API and 4 operations.
  3. Review and deploy.
curl -s -X POST localhost:8080/orders/get-order -H 'Content-Type: application/json' \
  -d '{"OrderId": "A-1001"}'
# {"OrderId":"A-1001","Status":"shipped","Customer":{"Name":"Ada Lovelace",…},"Lines":{"Line":[…]}}
curl -i -X POST localhost:8080/orders/get-order -H 'Content-Type: application/json' \
  -d '{"OrderId": "nope"}'
# 400 APX-SOAP-0002: the backend rejected the request (its fault is in the trace)

The JSON keys are the WSDL's element names. The caller sent JSON and got JSON; the envelope, the backend's fault and the SOAPAction header are in Analyze → Traffic on the soap step. The same operation by hand, in YAML:

operations:
  - name: get-order
    path: /get-order
    methods: [POST]
    policies:
      - type: soap
        config:
          action: urn:example:orders/GetOrder
          endpoint_path: /soap/orders
          namespaces: { ord: urn:example:orders }
          request: |
            <ord:GetOrder>
              <ord:OrderId>${body.OrderId}</ord:OrderId>
            </ord:GetOrder>
          response:
            unwrap: GetOrderResponse/Order
            arrays: [Line]

SOAP backends as JSON APIs has the template language, the conversion rules, faults, WS-Security and what the import leaves out.

Roll back

Deployments → History → Restore on an earlier deployment makes it live again and restores the draft from it. To roll back this API only, deploy an older revision from its Revisions tab.

apinxctl rollback 1

Watch it

The Traffic page listing recent requests with their status, caller and time The Traffic page listing recent requests with their status, caller and time 1 2 3 4

  1. The trace window. While it runs, every request keeps the decision of each policy step.
  2. Error reference explains every refusal code without leaving the page.
  3. Filter by route, application, status or a part of the path.
  4. A refused request stands out by its status. Click any row to open it in the request inspector.
  • Analyze → Traffic: every request, live. Open one for the timeline of policies and the backend call, with credentials redacted.
  • Analyze → Analytics: requests, errors and latency per minute, hour and day.
  • curl localhost:9000/metrics: Prometheus metrics per route, policy and upstream.

Next: The model explains what you just built.