Skip to content

A mobile backend, end to end

TutorialLearn by doing, one step after another.

This tutorial puts a real, public backend behind Apinx the way a mobile team would, and ends with a Postman collection the client developers can use. Everything here runs against the Test API at https://skyhubsoft.com/test-api (its OpenAPI reference), a small service with a three-step login that issues RS256 JWTs and an employee directory. Its data is static and its example credentials are published in its own documentation, so you can follow along on any instance.

The finished API is in the repository as examples/test-api/hr-mobile.api.yaml, with the collection examples/test-api/apinx-hr-mobile.postman_collection.json beside it.

What the app needs

# Requirement Where it lands
1 Login: 10 requests a minute rate-limit on the login operation, per client address
2 Everything else: 100 a minute rate-limit on the API, per signed-in user
3 Verify tokens against the backend's JWKS jwt on the API
4 Pass the user id to the backend transform: X-User-Id: ${claim.sub}
5 The app must not be able to set the user id the same transform removes the app's header first
6 Useful body transformations login answers reshaped, mobile numbers normalised, strings trimmed
7 Some operations take scope_full, some setup_scope required_scopes on the API, merge on the login steps
8 Anonymous operations stay anonymous jwt switched off on GET /employees/{id} and verify-token
9 Mask mobile numbers: 05xxxxxx01 jq on the responses
10 Do not expose the JWKS only the listed operations exist; the gateway reads the JWKS itself
11 A health endpoint built on the JWKS an active health check on the upstream, and GET /hr/health
12 The client is a mobile app short timeouts, small bodies, Cache-Control: no-store, OAuth-style token answers
13 Photo upload: token required, at most 100 KB, user id from the token request-size-limit on the upload operation
14 Photo download: token required, cached 5 minutes, user id from the token cache on the download operation; jwt inherited
15 Paged directory: the app POSTs, the backend serves GET transform: request.method: GET, body fields lifted to the query with ${body.…}
16 Every call carries a language, ar or en; names come back in it require-headers on the API; the response programs read request_headers["Accept-Language"] and fold fullNameAr into fullName

The backend

POST /api/auth/login          {username, password}          → setup_scope token (2 min)
POST /api/auth/verify-mobile  {mobileNumber}  + setup token → referenceKey
POST /api/auth/verify-pin     {pin} + ReferenceKey header   → scope_full token (30 min)
POST /api/auth/verify-token   {token}                       → anonymous
GET  /api/employees                            scope_full
GET  /api/employees/paged?pageNumber=&pageSize=  scope_full
GET  /api/employees/{id}                       anonymous
PUT  /api/employees/{id}                       scope_full
DELETE /api/employees/{id}                     scope_full
GET  /api/employees/{id}/image                 anonymous, image/png
POST /api/employees/{id}/image                 scope_full, multipart field `file`
GET  /.well-known/openid-configuration, /.well-known/jwks.json

Employees carry fullName and fullNameAr. Tokens carry iss: TestApi, aud: TestApi.Clients, sub (the user id), preferred_username and scope. The example account is admin / P@ssw0rd, mobile 0500000001, PIN 1234.

One fact about this backend shapes the configuration: it verifies the token itself. The gateway must forward it (strip: false); by default Apinx strips a validated token so a backend cannot replay it.

Step 1: the upstream

Develop → Upstreams → New upstream, then switch the panel to Code (YAML), paste the definition below and Create. The panel checks it as you type and names any mistake with its line. (In the Form, the same settings are under Show health, resilience, timeouts and TLS.)

apiVersion: apinx/v1
kind: Upstream
name: test-api
targets:
  - url: https://skyhubsoft.com/test-api
health:
  active:
    enabled: true
    interval: 10s
    timeout: 3s
    path: /.well-known/jwks.json     # 200 with keys = the application is up
    healthy_threshold: 1
    unhealthy_threshold: 2
  passive:
    enabled: true
    failures: 5
    eject_for: 30s
circuit_breaker:
  enabled: true
  failure_threshold: 5
  open_duration: 30s
retry:
  attempts: 1                        # idempotent methods only
  conditions: [connect_error, reset, "503"]
timeouts:
  connect: 5s
  response_header: 10s
  total: 15s                         # a phone should not wait longer

After saving, the Code view shows every setting of the upstream, defaults included.

The target URL carries the base path /test-api; every forwarded path, and the health check, goes under it. The active check is requirement 11 from the operator's side: Overview and the Gateway map show the backend red when its JWKS stops answering, and callers get 503 APX-UP-0001 instead of waiting on a dead service.

Step 2: the API

Develop → APIs → New API: name hr-mobile, base path /hr, upstream test-api, strip prefix on. Then open the API's Code tab, replace its content with the definition below, and Save to draft. The check that runs before saving names any mistake with the operation and field.

# The HR mobile API, as its owner writes it: paste into the API's Code tab
# (APIs → hr-mobile → Code) and save, or `PUT /api/v1/apis/{id}/definition`.
#
# It fronts the public Test API (https://skyhubsoft.com/test-api/scalar): a
# three-step login that issues RS256 JWTs, and an employee directory. The
# tutorial website/docs/tutorials/mobile-backend.md walks through every rule;
# the Postman collection beside this file exercises all of them.
#
# Needs an upstream named `test-api` pointing at https://skyhubsoft.com/test-api
# (the tutorial creates it with a health check on the JWKS).
#
# What the gateway enforces for the mobile app:
#   - login: 10 requests a minute per client address
#   - everything else: 100 requests a minute per signed-in user (the token's sub)
#   - tokens are verified against the backend's JWKS; setup_scope for the login
#     steps, scope_full for the directory, and only `admin` may delete
#   - the user id reaches the backend only from the verified token, never from a
#     header the app sent
#   - mobile numbers leave the gateway masked (05xxxxxx01); request bodies are
#     normalised (Saudi mobile formats, whitespace)
#   - employee photos: upload needs a token and at most 100 KB; download needs
#     a token and is cached for 5 minutes
#   - the paged directory is a POST for the app and a GET for the backend
#   - every call carries Accept-Language: ar or en (400 otherwise); names come
#     back in that language (fullNameAr is folded into fullName)
#   - GET /hr/api/employees/{id} and POST /hr/api/auth/verify-token stay anonymous
#   - the discovery and JWKS endpoints are not exposed; the gateway reads them
#   - GET /hr/health answers from the backend's JWKS: 200 up, 503 down

apiVersion: apinx/v1
kind: API
name: hr-mobile
description: Employee directory for the HR mobile app, on top of the Test API
hosts: ["*"]
base_path: /hr
upstream: test-api
strip_prefix: true

# Applied to every operation; an operation below changes what it must.
policies:
  # The app's contract: a language on every call, ar or en, nothing else.
  # The response programs below read it to choose the name's language.
  - type: require-headers
    config:
      required:
        Accept-Language: [ar, en]

  # Hostile payloads never reach the backend; phones send small bodies.
  - type: threat-protection
    config:
      max_body_bytes: 64KB
      json:
        max_depth: 8

  # The backend's own tokens. The backend verifies them too, so the token is
  # forwarded (strip: false). scope_full is the default requirement; the login
  # steps relax it to setup_scope and anonymous operations switch it off.
  - type: jwt
    config:
      issuer: TestApi
      audiences: [TestApi.Clients]
      jwks_url: https://skyhubsoft.com/test-api/.well-known/jwks.json
      algorithms: [RS256]
      required_scopes: [scope_full]
      strip: false

  # Per signed-in user (the token's sub). Anonymous operations set their own
  # per-address limit below.
  - type: rate-limit
    config:
      limit: 100
      window: 1m
      key: consumer
      trust_x_forwarded_for: true

  # Identity reaches the backend from the verified token only: whatever the
  # app sent in these headers is removed first; on anonymous operations the
  # empty claim leaves them out. Backend and CDN headers are dropped from
  # the answer, and phones are told not to cache directory data.
  - type: transform
    config:
      request:
        headers:
          remove: [X-User-Id, X-User-Name]
          set:
            X-User-Id: ${claim.sub}
            X-User-Name: ${claim.preferred_username}
      response:
        headers:
          remove: [Server, X-Powered-By, Nel, Report-To, CF-RAY, cf-cache-status, Alt-Svc]
          set:
            X-Served-By: apinx
            Cache-Control: no-store

  # Backend failures become the uniform error body, never a stack trace.
  - type: normalize-errors
    config:
      statuses: [5xx]

operations:
  # ---- Login: three steps, each with a different rule ----------------------

  # Step 1. No token yet, so the limit is per client address and tighter. The
  # answer is reshaped into the OAuth-style form the app expects, with a hint
  # for the next step.
  - name: login
    path: /api/auth/login
    methods: [POST]
    policies:
      - type: jwt
        enabled: false
      - type: rate-limit
        config:
          limit: 10
          window: 1m
          key: ip
          trust_x_forwarded_for: true
      - type: transform
        strategy: append
        config:
          response:
            body:
              program: |
                if .body.accessToken then {
                  access_token: .body.accessToken,
                  token_type: "Bearer",
                  expires_in: .body.expiresIn,
                  scope: .body.scope,
                  next_step: "POST /hr/api/auth/verify-mobile"
                } else .body end

  # Step 2. Needs the setup_scope token from step 1. The mobile number is
  # normalised before the backend sees it: spaces and dashes removed, +966 5…
  # and 966 5… become 05….
  - name: verify-mobile
    path: /api/auth/verify-mobile
    methods: [POST]
    policies:
      - type: jwt
        strategy: merge
        config:
          required_scopes: [setup_scope]
      - type: transform
        strategy: append
        config:
          request:
            body:
              program: |
                .body | if (.mobileNumber | type) == "string" then
                  .mobileNumber |= (gsub("[^0-9+]"; "")
                    | if startswith("+966") then "0" + .[4:]
                      elif startswith("966") then "0" + .[3:]
                      else . end)
                else . end
          response:
            body:
              program: |
                if .body.referenceKey then {
                  reference_key: .body.referenceKey,
                  expires_at: .body.expiresAtUtc,
                  next_step: "POST /hr/api/auth/verify-pin with header ReferenceKey"
                } else .body end

  # Step 3. The same setup_scope token plus the ReferenceKey header, which
  # passes through untouched. Answers with the scope_full token in the same
  # form as step 1.
  - name: verify-pin
    path: /api/auth/verify-pin
    methods: [POST]
    policies:
      - type: jwt
        strategy: merge
        config:
          required_scopes: [setup_scope]
      - type: transform
        strategy: append
        config:
          response:
            body:
              program: |
                if .body.accessToken then {
                  access_token: .body.accessToken,
                  token_type: "Bearer",
                  expires_in: .body.expiresIn,
                  scope: .body.scope
                } else .body end

  # Anonymous on the backend, anonymous here; limited per address.
  - name: verify-token
    path: /api/auth/verify-token
    methods: [POST]
    policies:
      - type: jwt
        enabled: false
      - type: rate-limit
        config:
          limit: 20
          window: 1m
          key: ip
          trust_x_forwarded_for: true

  # ---- Employee directory --------------------------------------------------

  # scope_full (inherited). The list is the same for every user, so it is
  # cached for 30 s after authentication: a cached answer is still only served
  # to a caller with a valid token. The API tells phones `Cache-Control:
  # no-store`; the gateway's own cache must not read that as an instruction,
  # hence respect_cache_control: false. Mobile numbers are masked on the way out.
  - name: employees-list
    path: /api/employees
    methods: [GET]
    policies:
      - type: cache
        config:
          ttl: 30s
          respect_cache_control: false
      - type: transform
        strategy: append
        config:
          response:
            body:
              program: |
                (.request_headers["Accept-Language"] // "" | ascii_downcase | startswith("ar")) as $ar
                | def localise: if (.fullNameAr | type) == "string" then .fullName = (if $ar then .fullNameAr else .fullName end) | del(.fullNameAr) else . end;
                def mask: if (.mobileNumber | type) == "string" and (.mobileNumber | length) > 4 then .mobileNumber |= (.[0:2] + ("x" * (length - 4)) + .[-2:]) else . end;
                if (.body | type) == "array" then .body | map(localise | mask) else .body end

  # scope_full (inherited). The app POSTs {pageNumber, pageSize}; the backend
  # serves the page on GET with query parameters. The method changes, the
  # body's fields move to the query and the body is dropped. The answer is
  # reshaped for the app and masked.
  - name: employees-paged
    path: /api/employees/paged
    methods: [POST]
    policies:
      - type: transform
        strategy: append
        config:
          request:
            method: GET
            query:
              set:
                pageNumber: ${body.pageNumber}
                pageSize: ${body.pageSize}
          response:
            body:
              program: |
                (.request_headers["Accept-Language"] // "" | ascii_downcase | startswith("ar")) as $ar
                | def localise: if (.fullNameAr | type) == "string" then .fullName = (if $ar then .fullNameAr else .fullName end) | del(.fullNameAr) else . end;
                def mask: if (.mobileNumber | type) == "string" and (.mobileNumber | length) > 4 then .mobileNumber |= (.[0:2] + ("x" * (length - 4)) + .[-2:]) else . end;
                if (.body.items | type) == "array" then {
                  items: (.body.items | map(localise | mask)),
                  page: {
                    number: .body.pageNumber, size: .body.pageSize,
                    total_count: .body.totalCount, total_pages: .body.totalPages,
                    has_next: .body.hasNextPage, has_previous: .body.hasPreviousPage
                  }
                } else .body end

  # The backend serves this one without a token, so does the gateway; the
  # limit is per address. The number is masked and the name localised here too.
  - name: employee-get
    path: /api/employees/{employeeId}
    methods: [GET]
    policies:
      - type: jwt
        enabled: false
      - type: rate-limit
        config:
          limit: 100
          window: 1m
          key: ip
          trust_x_forwarded_for: true
      - type: transform
        strategy: append
        config:
          response:
            body:
              program: |
                (.request_headers["Accept-Language"] // "" | ascii_downcase | startswith("ar")) as $ar
                | def localise: if (.fullNameAr | type) == "string" then .fullName = (if $ar then .fullNameAr else .fullName end) | del(.fullNameAr) else . end;
                def mask: if (.mobileNumber | type) == "string" and (.mobileNumber | length) > 4 then .mobileNumber |= (.[0:2] + ("x" * (length - 4)) + .[-2:]) else . end;
                if (.body | type) == "object" and (.body | has("employeeId")) then .body | localise | mask else .body end

  # scope_full. Strings are trimmed and the mobile number normalised before
  # the backend sees them (the backend wants both fullName and fullNameAr);
  # the answer is masked and localised like every other.
  - name: employee-update
    path: /api/employees/{employeeId}
    methods: [PUT]
    policies:
      - type: transform
        strategy: append
        config:
          request:
            body:
              program: |
                .body
                | with_entries(if (.value | type) == "string" then .value |= gsub("^\\s+|\\s+$"; "") else . end)
                | if (.mobileNumber | type) == "string" then
                    .mobileNumber |= (gsub("[^0-9+]"; "")
                      | if startswith("+966") then "0" + .[4:]
                        elif startswith("966") then "0" + .[3:]
                        else . end)
                  else . end
          response:
            body:
              program: |
                (.request_headers["Accept-Language"] // "" | ascii_downcase | startswith("ar")) as $ar
                | def localise: if (.fullNameAr | type) == "string" then .fullName = (if $ar then .fullNameAr else .fullName end) | del(.fullNameAr) else . end;
                def mask: if (.mobileNumber | type) == "string" and (.mobileNumber | length) > 4 then .mobileNumber |= (.[0:2] + ("x" * (length - 4)) + .[-2:]) else . end;
                if (.body | type) == "object" and (.body | has("employeeId")) then .body | localise | mask else .body end

  # scope_full and the administrator account only: a claim rule on top of the
  # scope rule.
  - name: employee-delete
    path: /api/employees/{employeeId}
    methods: [DELETE]
    policies:
      - type: jwt
        strategy: merge
        config:
          required_claims:
            preferred_username: [admin]

  # ---- Employee photos -----------------------------------------------------

  # scope_full (inherited), so the backend receives X-User-Id from the token
  # even though it would serve the picture anonymously. The same picture for
  # every caller, so one cached copy serves everyone for 5 minutes; the
  # no-store the API sends to phones is not an instruction to this cache.
  - name: image-download
    path: /api/employees/{employeeId}/image
    methods: [GET]
    policies:
      - type: cache
        config:
          ttl: 5m
          respect_cache_control: false

  # scope_full (inherited) and X-User-Id from the token. The multipart body
  # may not exceed 100 KB: request-size-limit refuses a declared length above
  # it before reading, and cuts off an undeclared one at the limit (413);
  # threat-protection's own ceiling, 64 KB for the rest of the API, is raised
  # to match.
  - name: image-upload
    path: /api/employees/{employeeId}/image
    methods: [POST]
    policies:
      - type: request-size-limit
        config:
          max_bytes: 100KB
      - type: threat-protection
        strategy: merge
        config:
          max_body_bytes: 100KB

  # ---- Health -------------------------------------------------------------

  # Anonymous. Rewritten to the backend's JWKS: keys present means the
  # application is up (200), anything else is 503. Cached for 10 s so a
  # monitoring probe never adds load to the backend.
  - name: health
    path: /health
    methods: [GET]
    policies:
      - type: jwt
        enabled: false
      - type: require-headers
        enabled: false             # monitoring probes send no language
      - type: rate-limit
        config:
          limit: 30
          window: 1m
          key: ip
          trust_x_forwarded_for: true
      - type: cache
        config:
          ttl: 10s
          statuses: ["200"]
          respect_cache_control: false
      - type: transform
        strategy: append
        config:
          request:
            path:
              replace:
                pattern: ^/health$
                with: /.well-known/jwks.json
          response:
            body:
              program: |
                {
                  status: (if ((.body.keys // []) | length) > 0 then "up" else "down" end),
                  signing_keys: ((.body.keys // []) | length),
                  checked_at: (now | todate)
                }
            status:
              when:
                - if: ((.body.keys // []) | length) == 0
                  status: 503

What the API-level policies do

Every operation inherits these; an operation changes only what it must.

  • require-headers (requirement 16): Accept-Language must be present and be ar or en; anything else is 400 APX-PL-0027 naming the header and the allowed values, before any other policy runs. The health operation switches it off: monitoring probes send no language.
  • threat-protection: oversized or deeply nested JSON, XXE and injection patterns are refused before the backend sees them. Phones send small bodies, so 64 KB is plenty.
  • jwt (requirements 3, 7): signature against the backend's JWKS, issuer, audience, expiry. required_scopes: [scope_full] is the default; the login steps narrow it to setup_scope with strategy: merge, which keeps the issuer and keys and changes only the scope. strip: false because this backend verifies the token too.
  • rate-limit (requirement 2): key: consumer counts per authenticated subject, so one user cannot starve another. trust_x_forwarded_for is on because the gateway sits behind a reverse proxy or CDN in production; leave it off when callers reach the gateway directly.
  • transform (requirements 4, 5): X-User-Id and X-User-Name are removed from the incoming request, then set from the verified claims. On anonymous operations the claim is empty and the header is left out, so the backend never receives a user id the app invented. On the way back, backend and CDN headers (Server, CF-RAY, Nel, …) are dropped and Cache-Control: no-store tells the phone not to keep directory data.
  • normalize-errors: a backend 5xx becomes the uniform Apinx error body with a correlation id, never a stack trace.

What each operation changes

Operation Changes Why
login jwt off; rate-limit 10/min per address; response reshaped No token yet (1). The answer becomes {access_token, token_type, expires_in, scope, next_step}, the form a mobile OAuth client already understands
verify-mobile jwt merge → setup_scope; request body normalised; response reshaped +966 50-000-0001, 966500000001 and 0500000001 all become 0500000001 before the backend compares them (6)
verify-pin jwt merge → setup_scope; response reshaped The ReferenceKey header passes through untouched
verify-token jwt off; 20/min per address Anonymous on the backend, anonymous here (8)
employees-list cache 30 s; response masked The list is the same for every user, so one backend call serves everyone for 30 s. The cache runs after authentication: a cached answer is still only served to a valid token. The gateway adds Cache-Control: no-store for phones, so the cache is told not to read that header as an instruction (respect_cache_control: false)
employees-paged transform: method: GET, pageNumber: ${body.pageNumber}, pageSize: ${body.pageSize}; response reshaped and masked The app POSTs {pageNumber, pageSize}; the backend receives GET …/paged?pageNumber=2&pageSize=3 and no body (15). The answer becomes {items, page: {number, size, total_count, total_pages, has_next, has_previous}}
employee-get jwt off; 100/min per address; response masked Anonymous (8), masked (9)
employee-update request body normalised; response masked Trimmed strings, normalised mobile (6)
employee-delete jwt merge → required_claims: {preferred_username: [admin]} A claim rule on top of the scope rule: only the administrator account may delete
image-download cache 5 min The backend serves the picture anonymously; the gateway requires the token (14) so the backend always receives X-User-Id. One cached copy serves every user; RateLimit-* still counts each call
image-upload request-size-limit 100 KB; threat-protection merge → 100 KB A declared length above the limit is refused before a byte is read; an undeclared one is cut off at the limit (413). The API-wide 64 KB ceiling is raised for this operation only (13)
health jwt off; path rewritten to /.well-known/jwks.json; body and status from the keys; cached 10 s Requirement 11 for monitoring tools: {status: up, signing_keys: 1} with 200, or 503 when no key comes back. The 10 s cache means a probe every second costs the backend one call

Two small jq functions are used on every response that carries an employee:

(.request_headers["Accept-Language"] // "" | ascii_downcase | startswith("ar")) as $ar
| def localise: if (.fullNameAr | type) == "string"
                then .fullName = (if $ar then .fullNameAr else .fullName end) | del(.fullNameAr)
                else . end;
  def mask: .mobileNumber |= (.[0:2] + ("x" * (length - 4)) + .[-2:]);    # 0551000001 → 05xxxxxx01

request_headers is the request as the backend received it, available to response programs, so the language the app asked for decides which name it gets; the other name never leaves the gateway.

Every body program is guarded (if (.body | type) == "array" …) so an error body from the backend passes through unchanged instead of failing the transformation.

Step 3: deploy and try it

Deploy from the API page or Develop → Deployments. Then, with the proxy on localhost:8080:

curl -s localhost:8080/hr/health
{"checked_at":"2026-10-01T09:04:11Z","signing_keys":1,"status":"up"}

curl -s localhost:8080/hr/api/employees/1001 -H 'Accept-Language: ar'
{"department":"Engineering","email":"ahmed.alharbi@example.com","employeeId":1001,"employmentDate":"2019-03-10","fullName":"أحمد الحربي","jobTitle":"Senior Developer","mobileNumber":"05xxxxxx01"}

Without the header, or with fr, the answer is 400 APX-PL-0027 with details.header: Accept-Language and details.allowed: [ar, en]. Every call below carries Accept-Language: ar or en.

curl -s -X POST localhost:8080/hr/api/auth/login -H 'Content-Type: application/json' \
  -d '{"username":"admin","password":"P@ssw0rd"}'
{"access_token":"eyJhbGciOiJS…","expires_in":120,"next_step":"POST /hr/api/auth/verify-mobile","scope":"setup_scope","token_type":"Bearer"}

With that token, GET /hr/api/employees answers 403 APX-PL-0003: valid token, wrong scope. Continue with verify-mobile ({"mobileNumber":"+966 50-000-0001"}) and verify-pin ({"pin":"1234"} plus the ReferenceKey header) to get the scope_full token, and the list answers 200 with every number masked, RateLimit-Limit: 100, X-Cache: MISS then HIT.

Eleven logins with a wrong password in one minute:

401 401 401 401 401 401 401 401 401 429 429

The ninth 401 is the tenth login in the window, counting the successful one above; the gateway refuses the rest with Retry-After. GET /hr/.well-known/jwks.json is 404 APX-RT-0001: only the operations you listed exist.

Open Analyze → Traffic and click any of these requests: the timeline shows each policy's decision, the headers as the backend received them (X-User-Id: 1, no X-User-Id: 999 however hard the app tried), the jq steps with their duration, and a cURL to repeat the call.

Step 4: the Postman collection for the client team

The console generates a collection for any API: APIs → hr-mobile → Postman in the page header, with the address callers use (https://api.example.com). It has one request per operation with the bearer token and Accept-Language already in place as variables, and it follows the policies: login, verify-token, the anonymous employee lookup and health carry no token. Try it on any row of the Operations tab does the same for a single request, sends it through the gateway, and gives the cURL.

The hand-written collection below goes further: it chains the three login steps and asserts what the gateway guarantees.

Import examples/test-api/apinx-hr-mobile.postman_collection.json. It carries the collection variables (baseUrl, the example account, lang for the language every request sends) and chains the tokens itself: run the folders in order, or the whole collection in the Runner. Every request has tests that state what the gateway guarantees, so the collection doubles as the contract the mobile developers build against:

Folder Requests Asserts
1 · Health backend health 200, status: up, cached
2 · Login the three steps and verify-token shapes, scopes, RateLimit-Limit: 10, tokens stored in variables
3 · Employees list, list again, page, get one, update, delete masking, X-Cache: HIT, POST→GET paging, trimmed fields, admin-only delete
4 · Employee photos download, download without a token, upload, upload over 100 KB image/png cached, 401, 200, 413
5 · Refusals no language, fr, no token, setup token, JWKS, wrong password 400 APX-PL-0027, 401 APX-PL-0001, 403 APX-PL-0003, 404 APX-RT-0001, 429

The upload requests reference examples/test-api/avatar.png (a 16×16 PNG) and examples/test-api/too-large.png (110 KB); Postman resolves them relative to its working directory, so pick the files in the Body tab if it cannot find them. From the command line, the same collection runs with newman from the repository root:

npx newman run examples/test-api/apinx-hr-mobile.postman_collection.json --env-var baseUrl=http://localhost:8080

Decisions worth knowing

  • Why not expose the JWKS? The app never needs it; it needs tokens, and those come from login. Exposing fewer endpoints is less to protect. Add an operation for /.well-known/jwks.json if a partner must verify tokens itself.
  • Why forward the token? This backend authorises by itself. If yours trusts the gateway instead, leave strip at its default and let X-User-Id carry the identity; the backend then never sees a credential it could leak.
  • Where the rate limits count. Per user for the directory, per address for anything a user cannot be known on yet. Behind Cloudflare or nginx, trust_x_forwarded_for makes the address the real client's; without a proxy, switch it off so a caller cannot choose their own address.
  • Cost. Header rules are microseconds. The jq programs run only on the operations that bind them and only on bodies under 64 KB; the trace shows their time, well under a millisecond here. Nothing in this API touches the database on the request path.

Going further