Prompt
How do I expose a core product capability through an API?
Latest observation
To expose a core product capability through an API, think of it as turning a business capability into a stable product interface. The key is not just “making endpoints,” but designing something that is safe, useful, secure, and maintainable for both internal and external consumers.
1) Start with the capability, not the technology
Identify the exact business capability you want to expose.
Examples:
- Create an order
- Verify a user identity
- Reserve inventory
- Calculate a quote
- Issue a refund
Define:
- What problem it solves
- Who uses it
- What inputs it needs
- What outputs it returns
- What success and failure look like
Avoid exposing internal tables, microservice boundaries, or implementation details.
2) Define the API contract
Write a clear contract before implementation.
Include:
- Resource names and verbs
- Request/response schemas
- Error formats
- Authentication/authorization rules
- Idempotency expectations
- Rate limits
- Versioning strategy
A good contract answers:
- What can clients do?
- What data do they need?
- What do they get back?
- How will changes be handled?
3) Model the API around the domain
Use domain language that business and engineering both understand.
For example:
- Prefer
POST /quotesoverPOST /pricing-engine/run - Prefer
POST /transfersoverPOST /ledgerEntries
Good APIs reflect the business capability, not the internals.
4) Decide synchronous vs asynchronous
Choose based on latency and business workflow.
Use synchronous APIs when:
- The result is immediate
- Clients need an answer right away
- Operations are fast and deterministic
Use asynchronous APIs when:
- Work is long-running
- There are external dependencies
- You need resilience or retries
For async APIs, provide:
- A job/status endpoint
- Webhooks or callbacks if needed
- Clear state transitions
5) Design for reliability
Core capabilities should be dependable.
Include:
- Idempotency keys for create/charge/submit actions
- Retries with safe semantics
- Timeouts
- Circuit breakers / fallback behavior
- Consistent error codes
- Observability: logs, metrics, tracing
This is especially important for business-critical actions like payments or order creation.
6) Secure it properly
Protect the capability based on sensitivity.
Consider:
- OAuth2 / OIDC for user-delegated access
- API keys for simple server-to-server use
- mTLS for high-trust integrations
- Fine-grained authorization scopes/roles
- Input validation
- Encryption in transit and at rest
Also define:
- Which fields are sensitive
- Which clients can access them
- Audit logging requirements
7) Design for versioning and change
Core capabilities evolve, so plan for change from day one.
Best practices:
- Avoid breaking changes in-place
- Use additive changes when possible
- Version your API if needed (
/v1/...) - Deprecate with clear timelines
- Maintain backward compatibility where practical
8) Make it easy for consumers
A capability is only valuable if others can use it easily.
Provide:
- Developer documentation
- Examples and sample payloads
- SDKs or client libraries if useful
- Postman/Swagger/OpenAPI specs
- Sandbox environment
- Test credentials or mock endpoints
9) Put governance around it
Since it’s a core capability, treat it as a product.
Define:
- API owner
- SLA/SLO
- Support process
- Change approval process
- Deprecation policy
- Monitoring and incident response
10) Validate with real use cases
Before broad release, test with actual consumer scenarios.
Ask:
- Does this API support the workflows users need?
- Are there missing fields or actions?
- Is the error handling clear?
- Is it too chatty or too rigid?
- Does it expose enough without exposing too much?
Practical checklist
Before exposing the API, make sure you have:
- Clear business capability definition
- Domain-oriented API design
- OpenAPI/contract specification
- Authentication and authorization
- Input validation and error model
- Idempotency and retries
- Monitoring and audit logs
- Versioning and deprecation plan
- Documentation and examples
- SLA/support ownership
Example framing
If the capability is “approve a loan,” a good API might expose:
POST /loan-applicationsGET /loan-applications/{id}POST /loan-applications/{id}/approvePOST /loan-applications/{id}/reject
That is much better than exposing internal service methods like:
runRiskEngine()persistLoanDecision()updateWorkflowState()
If you want, I can also give you:
- a step-by-step API design template,
- a sample OpenAPI spec, or
- guidance for exposing a capability as an internal vs external API.