A Service REST rule lets other systems call into your Pega application over HTTP. Where Connect-REST is Pega calling out, Service REST is Pega answering. A mobile app, a website or a partner system can then read or create cases and data through a URL.
The pieces you need
| Rule | Job |
|---|---|
| Service Package | The container. It sets the authentication method and the processing mode (stateless or stateful) |
| Service REST | Defines the resource path and, for each HTTP method, the activity or data page that responds |
| Service activity or data page | Does the work: reads or writes clipboard data |
| Data transforms or mapping | Convert JSON in the request and response to and from clipboard properties |
Building one
- Create or choose a Service Package and set authentication, for example basic or OAuth 2.0.
- Create a Service REST rule in that package. Give it a resource path, such as
customers/{id}, where{id}is a path parameter. - For each method you support, such as GET or POST, choose the service activity or data page and map the request and response data.
- Set the response status codes for success and for errors.
- Test with a tool such as Postman or curl, then publish the URL to the consumers.
A worked example
A bank wants a partner app to check a loan status.
- Resource path:
loans/{loanId}/status, method GET. - The service calls a data page
D_LoanStatuswithloanIdas its parameter. - The response mapping returns JSON such as
{"loanId":"L-101","status":"Approved"}with status 200. - If no loan exists, the service returns 404 with a short message instead of a Pega error page.
Good practice
- Always require authentication and give the service account only the rights it needs.
- Version your APIs, for example
/v1/loans, so you can change them safely. - Validate the request and return clear error codes and messages.
- Prefer stateless services and make each call carry its own context.
- Log request IDs to help support trace a problem.
Interview tip
Name the rule chain: Service Package, Service REST, then the activity or data page and the mapping. Add one example URL. Read on: GET, POST, PUT, PATCH and DELETE in Pega integration.
No comments:
Post a Comment