Chapter 9 Service API and Contract Design With RS and Microservice - En
Chapter 9 Service API and Contract Design With RS and Microservice - En
with
REST Services and Microservices
[email protected]
1. Service Model Design Considerations
Entity Service Design
• REST Entity Services defines a • Example
functional boundary for business • Invoice entity service with two
entities standard HTTP methods and two
• Primarily handles data processing complex methods
related to the entity
• Uses idempotent HTTP methods
(GET, PUT, DELETE) for reliability
• Complex Methods (Optional): If
allowed by service inventory’s design
standards
Utility Service Design
• Utility Services • Example: HR System Utility
• Reusable & agnostic, but without a Service
fixed functional scope • Retrieves employee data from a
• Validate method-resource choices legacy HR system
before finalizing • Used by other services for employee
info
• Characteristics
• Flexible boundaries, often wrapping
legacy systems
• Provides read-only access to legacy
data
• SOA Patterns
• Dual Protocols
• Concurrent Contracts
• Service Façade
• Legacy Wrapper
Microservice Design
• Microservice • Example: Confirm Authorization
• Non-agnostic – Designed for specific • A microservice contract with a
business processes singlepurpose, non-agnostic
• Limited consumers – Often serves only functional scope
one service
• Flexibility in contract design –
Standardization is optional
• Challenges
• Ensuring performance & reliability and
runtime efficiency
• SOA & Microservice Patterns
• Microservice Deployment
• Containerization
• Service Data Replication
• Redundant Implementation
Task Service Design
• Task Service Design in REST • Example: Validate Timesheet Task
APIs Service
• Single-purpose – Often limited to one • Trigger
key function • Check Status
• Triggered by POST requests – • Cancel Task
Requires reliability measures
• Handling Asynchronous
Processes
• For long-running tasks
• State tracking capabilities – Using
additional service endpoints
• Cancellation support – Allows
stopping active processes
2. CASE STUDY EXAMPLE
MUA Confer Student Award
• The service modeling process
performed by MUA produced a
number of REST service
candidates
• The codes and reasons provided • But, HTTP does not define how
by HTTP are standardized consumers should react to codes
• HTTP Response Code Ranges & → needs standardization
Their Meaning • SOA projects must enforce
• 100-199 → Informational consistent response code
• 200-299 → Success handling
• 300-399 → Redirection
• 400-499 → Client Errors
• 500-599 → Server Errors
• Standardized HTTP response
codes ensure predictable, efficient
REST API behavior
Customizing Response Codes
• The HTTP specification allows • Guideline for Custom Response
for extensions to response codes Codes
• Custom codes should follow existing • Keep codes uniform
HTTP ranges • Make response messages human-
readable
• Ensure reusability
• Avoid code conflicts
• Introduce codes only when necessary
• Thoughtful customization
improves REST API clarity &
consistency while maintaining
compatibility!
Designing Media Types
• Importance of Media Types in • Guideline for Defining Media
Service Inventories Types
• Media types change more frequently • Use existing media types when
than methods possible
• Standard Web Media Types for • Media types should be schema-
specific
Service Inventories
• Keep them abstract
• text/plain; charset=utf-8
• Enable extensibility
• application/xhtml+xml
• Provide standard processing
• application/json instructions
• text/uri-list
• application/atom+xml
Designing Media Types (2)
• Custom Media Type Naming Convention
• Format: application/vnd.organization.type+supertype
• Example:
• application/vnd.com.examplebooks.purchase-order+xml
• application → Machine-readable format.
• vnd.com.examplebooks → Vendor namespace (examplebooks.com)
• purchase-order → Media type name.
• +xml → Derived from XML (compatible with XML parsers).